#include <iostream>
using namespace std; class Dummy
{
public:
int x;
Dummy()
: x()
{
}
;
Dummy(int xx)
: x(xx)
{
}
;
bool isitem(Dummy const&);
Dummy& operator=(Dummy const& param);
};
bool Dummy::isitem(Dummy const& param)
{
if(this == &param)
return true;
return false;
}
Dummy& Dummy::operator=(const Dummy& param)
{
this->x = param.x;
cout << "=" << endl;
//this指向等号左边的对象
return *this;
} int main()
{
Dummy a;
Dummy* b = &a;
if(b->isitem(a))
cout << true << endl;
else
cout << false << endl;
Dummy foo();
Dummy bar;
//声明一个对象,然后把foo赋值给它
// Dummy bar=foo;
//调用重载函数=
// bar.operator =(foo);
//调用重载函数=
bar = foo;
cout << bar.x << endl;
cout << bar.isitem(foo) << endl;
cout << bar.isitem(bar) << endl;
return ;
}
05-11 17:56