您的位置:首页 > 编程语言 > C语言/C++

c++类默认拷贝构造函数---浅复制

2016-01-25 15:12 363 查看
类默认的拷贝构造函数是浅复制,比如如下程序,类中指向的地址是一样的

[code]#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; 
}





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: