#include <iostream>
using namespace std;
class test{
public:
test(){
cout << "constructor" << endl;
}
test(const test& a)
{
cout << "copy constructor" << endl;
}
~test(){}
test& operator = (const test& a)
{
if(this != &a){
cout << "=operator" << endl;
return *this;
}
}
};
int main()
{
test a; //constructor
test b(a); // copy constructor
test c = test(a); // copy constructor
test d = a; // copy constructor
test* e = new test(a); // copy constructor
test f; //constructor
f = a; // = operator overload
}
运行结果: