1、
#include <iostream>
using namespace std;
class stu
{
public:
int* a;
stu()
{
a = new int[3];
a[0] = 12;
a[1] = 134;
}
stu(const stu& b)//拷贝构造
{
this->a = new int[2];
this->a[0] = b.a[0];
this->a[1] = b.a[1];
//memcpy(this->a,b.a,sizeof(a)*2); 内存拷贝
}
~stu()
{
delete[] a;
}
};
int main()
{
{stu db;
cout << db.a[0] << " " << db.a[1] << endl;
stu db1(db);
cout << db1.a[0] << " " << db1.a[1] << endl;
system("pause");
}
return 0;
}