拷贝构造函数
拷贝构造函数实现了自己定义的类对象赋值给另一个对象
#include <iostream>
using namespace std;
class Test
{
public:
int p1;
Test(int temp)
{
p1 = temp;
}
//自定义的拷贝构造函数
Test(Test& c_t)
{
cout << "进入copy构造函数" << endl;
p1 = c_t.p1;
}
};
int main()
{
Test a(52014314);
Test b = a;
cout << b.p1;
cout << endl;
system("pause");
return 0;
}
转载自:黑凤梨の博客