浅拷贝:简单的赋值拷贝操作
#include<iostream>
using namespace std;
//深拷贝与浅拷贝问题
class person
{
public:
person()
{
cout << "构造函数" << endl;
}
person(int age1)
{
age2 = age1;
cout << "有参函数" << endl;
}
~person()
{
cout << "析构函数" << endl;
}
int age2;
};
void test()
{
person p(18);
cout << "p的年龄为:" << p.age2 << endl;
person p1(p);//浅拷贝
cout << "p1的年龄为:" << p1.age2 << endl;
}
int main() {
test();
system("pause"