#include "iostream"
using namespace std;
class test
{
private:
int data;
public:
test(int arg);
test operator = (const test &temp);//赋值函数
test(const test &temp);//拷贝构造函数
/* data */
};
test::test(int temp){
cout<<"构造函数"<<endl;
data = temp;
}
test test::operator = (const test &temp){
cout<<"赋值函数"<<endl;
data = temp.data;
}
test::test(const test &temp){
cout<<"拷贝构造函数"<<endl;
data = temp.data;
}
int main(int argc, char const *argv[])
{
test t1(100);
test t2(200);
test t3(t1);//调用构造函数,t3为新对象
t3 = t2;//调用赋值函数
system("pause");
return 0;
}
赋值函数和拷贝赋值函数
最新推荐文章于 2024-06-09 16:08:11 发布