类默认的拷贝构造函数是浅复制,比如如下程序,类中指向的地址是一样的
#include <iostream>
using namespace std;
class Test
{
public:
int *a;
};
int main()
{
Test *t = new Test();
int aa = 1314520;
t->a = &aa;
Test *t2 = new Test(*t);
cout<<t->a<<endl;
cout<<t2->a<<endl;
return 0;
}
时间: 2024-09-17 03:22:12