[over.ass] (original) (raw)

12 Overloading [over]

12.6 Overloaded operators [over.oper]

12.6.2 Binary operators [over.binary]

12.6.2.1 Simple assignment [over.ass]

A simple assignment operator functionis a binary operator function named operator=.

A simple assignment operator function shall be a non-static member function.

[ Note

:

Because only standard conversion sequences are considered when converting to the left operand of an assignment operation ([over.best.ics]), an expression x = y with a subexpression x of class type is always interpreted as x.operator=(y).

end note

]

[ Note

:

Since a copy assignment operator is implicitly declared for a class if not declared by the user ([class.copy.assign]), a base class assignment operator function is always hidden by the copy assignment operator function of the derived class.

end note

]

[ Note

:

Any assignment operator function, even the copy and move assignment operators, can be virtual.

For a derived class D with a base class Bfor which a virtual copy/move assignment has been declared, the copy/move assignment operator in D does not overrideB's virtual copy/move assignment operator.

[ Example

:

struct B { virtual int operator= (int); virtual B& operator= (const B&); }; struct D : B { virtual int operator= (int); virtual D& operator= (const B&); };

D dobj1; D dobj2; B* bptr = &dobj1; void f() { bptr->operator=(99);
*bptr = 99;
bptr->operator=(dobj2);
*bptr = dobj2;
dobj1 = dobj2;
}

end example

]

end note

]