Оператор назначения перегрузки в связанном списке - PullRequest
0 голосов
/ 03 марта 2019
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;
}

Может кто-нибудь предложить правильный синтаксис или что-то, что могло бы заставить этот код работать?

...