先来代码:
#include <iostream>
using namespace std;
class CA
{
public:
CA(int b)
{
cout << "constructure" << endl;
a=b;
}
CA(const CA& C) // 拷贝构造函数
//必须传引用 ,如果传值,就会要求构造临时对象,需要调用拷贝构造,又传值,又调用拷贝构造。。。
{
cout << "copy constructure" << endl;
a=C.a;
}
CA& operator=(const CA& C)//重写operator=
{
cout << "operator =" << endl;
a = C.a;
return *this;
}
void Show()
{
cout<<a<