60 lines
2.4 KiB
Markdown
60 lines
2.4 KiB
Markdown
[over.assign]
|
||
|
||
# 12 Overloading [[over]](./#over)
|
||
|
||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.assign)
|
||
|
||
### 12.4.3 Binary operators [[over.binary]](over.binary#over.assign)
|
||
|
||
#### 12.4.3.2 Simple assignment [over.assign]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3566)
|
||
|
||
A [*simple assignment operator function*](#def:operator_function,simple_assignment "12.4.3.2 Simple assignment [over.assign]") is a binary operator function named operator=[.](#1.sentence-1)
|
||
|
||
A simple assignment operator function shall be a non-static member function[.](#1.sentence-2)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
Because only standard conversion sequences are considered when converting
|
||
to the left operand of an assignment operation ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")),
|
||
an expression x = y with a subexpression x of class type
|
||
is always interpreted as x.operator=(y)[.](#1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3577)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
Since a copy assignment operator is implicitly declared for a class
|
||
if not declared by the user ([[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")),
|
||
a base class assignment operator function is always hidden by
|
||
the copy assignment operator function of the derived class[.](#2.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3585)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
Any assignment operator function, even the copy and move assignment operators,
|
||
can be virtual[.](#3.sentence-1)
|
||
|
||
For a derived class D with a base class B for 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[.](#3.sentence-2)
|
||
|
||
[*Example [1](#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); // calls D::operator=(int)*bptr = 99; // ditto bptr->operator=(dobj2); // calls D::operator=(const B&)*bptr = dobj2; // ditto dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)} â *end example*]
|
||
|
||
â *end note*]
|