#ifndef
#define
#include <iostream>
using namespace std;
class A {
public:
int a;
A();
A(int a);
A(A &a1);
A &operator= (A &a1);//注意必须加引用,自己感受编译带来效果

};
#endif
#include "A.h"
A::A() {

}

A::A(int a1) {
this->a = a1;
}

A::A(A &a1) {//拷贝构造函数
this->a= a1.a;
cout << "A::A(A &a1) a= " << this->a << endl;
}

A &A::operator=(A &a2) {//运算符重载
this->a = a2.a;
cout << "A::operator=(A a2) a = " << this->a << endl;
return *this;
}
#include "A.h"

void fun() {
A a1(1);
cout << "----------1-----------" << endl;
A a2;
cout << "----------2-----------" << endl;
a2 = a1;//赋值构造函数
cout << "----------3------------" << endl;

A a3(a1);//复制,拷贝构造函数
cout << "----------4------------" << endl;
}

/*不能重载的运算符只有五个,
它们是:成员运算符“.”、指针运算符“*”、作用域运算符“::”、“sizeof”、条件运算符“?:”。*/

int main() {

fun();

return 0;
}