[over.binary] (original) (raw)

12.4.3.1 General [over.binary.general]

A binary operator functionis a function named operator@for a binary operator @ that is either a non-static member function ([class.mfct]) with one non-object parameter or a non-member function with two parameters.

For an expression x @ y with subexpressions x and y, the operator function is selected by overload resolution ([over.match.oper]).

If a member function is selected, the expression is interpreted as

x . operator @ ( y )

Otherwise, if a non-member function is selected, the expression is interpreted as

operator @ ( x , y )

An equality operator function is an operator function for an equality operator ([expr.eq]).

A relational operator function is an operator function for a relational operator ([expr.rel]).

A three-way comparison operator function is an operator function for the three-way comparison operator ([expr.spaceship]).

A comparison operator function is an equality operator function, a relational operator function, or a three-way comparison operator function.

12.4.3.2 Simple assignment [over.assign]

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

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

[Note 1:

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 2:

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 3:

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 1: 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_]