C++构造函数问题5

以下程序的输出?

null

#include<iostream>
using namespace std;
class Point {
public :
Point() { cout << "Normal Constructor called" ; }
Point( const Point &t) { cout << "Copy constructor called" ; }
};
int main()
{
Point *t1, *t2;
t1 = new Point();
t2 = new Point(*t1);
Point t3 = *t1;
Point t4;
t4 = t3;
return 0;
}


(A) 正常构造函数调用 正常构造函数调用 正常构造函数调用 复制构造函数调用 复制构造函数调用 正常构造函数调用 复制构造函数调用 (B) 正常构造函数调用 复制构造函数调用 复制构造函数调用 正常构造函数调用 复制构造函数调用 (C) 正常构造函数调用 复制构造函数调用 复制构造函数调用 正常构造函数调用 答复: (C) 说明: 有关解释,请参见以下注释:

Point *t1, *t2;   // No constructor call
t1 = new Point(10, 15);  // Normal constructor call
t2 = new Point(*t1);   // Copy constructor call 
Point t3 = *t1;  // Copy Constructor call
Point t4;   // Normal Constructor call
t4 = t3;   // Assignment operator call 

这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享