class Attribute
{
public:
string data;
Attribute *next;
Attribute& operator = (const Attribute *attr)
{
data = "dummy";
this->next = NULL;
return *this;
}
};
int main()
{
Attribute* atr = new Attribute("abc");
Attribute* atr2 = new Attribute("123");
atr2 = atr;
atr->data = "etr";
cout << atr2->data << endl; // Output should be "dummy" but it is "etr"
system("pause");
return 0;
}
有人可以建议正确的语法还是可以使此代码起作用的内容?