#include <iostream>
using namespace std;
class base {
private:
int a;
public:
base(int x=0):a(x) { cout<< "base construct function:" << a << endl; }
base(const base &b){
a = b.a;
cout<< "in copy constructor fuction" << endl;
}
base & operator=(const base &b);
void show(){cout << a << endl;}
};
base& base::operator=(const base &b){
cout<< "in assign = function: " << endl;
a = b.a;
return *this;
}
int main()
{
base a(1);
base b(2);
base c(3);
base d = a;
c = a;
base e(a);
base f;
a.show();
b.show();
c.show();
d.show();
e.show();
f.show();
cout << "Hello world!" << endl;
return 0;
}
C++中的拷贝构造函数和赋值操作符
最新推荐文章于 2024-09-10 00:30:00 发布