【发布时间】:2013-11-05 09:26:44
【问题描述】:
我创建了一个类类型Test和带参数的构造函数,但是,当我想通过函数f将我创建的构造函数分配给一个新的构造函数时,程序崩溃了!有人知道为什么吗!?
代码:
class Test
{
public:
int number;
int *a;
Test(int n){
a = new int[n];
}
~Test(){
delete []a;
}
};
Test f(Test Ft1)
{
// Do something.
return Ft1;
}
int main()
{
Test t1(3);
t1.number = 5;
Test t2 = f(t1);
return 0;
}
【问题讨论】:
标签: c++ function class constructor dynamic-arrays