tmp/tmp4g4485hk/{from.md → to.md}
RENAMED
|
@@ -5,14 +5,20 @@ function with exactly one parameter. Because a copy assignment operator
|
|
| 5 |
`operator=` is implicitly declared for a class if not declared by the
|
| 6 |
user ([[class.copy]]), a base class assignment operator is always
|
| 7 |
hidden by the copy assignment operator of the derived class.
|
| 8 |
|
| 9 |
Any assignment operator, even the copy and move assignment operators,
|
| 10 |
-
can be virtual.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
struct B {
|
| 17 |
virtual int operator= (int);
|
| 18 |
virtual B& operator= (const B&);
|
|
@@ -28,10 +34,13 @@ B* bptr = &dobj1;
|
|
| 28 |
void f() {
|
| 29 |
bptr->operator=(99); // calls D::operator=(int)
|
| 30 |
*bptr = 99; // ditto
|
| 31 |
bptr->operator=(dobj2); // calls D::operator=(const B&)
|
| 32 |
*bptr = dobj2; // ditto
|
| 33 |
-
dobj1 = dobj2; // calls implicitly-declared
|
| 34 |
-
// D::operator=(const D&)
|
| 35 |
}
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
`operator=` is implicitly declared for a class if not declared by the
|
| 6 |
user ([[class.copy]]), a base class assignment operator is always
|
| 7 |
hidden by the copy assignment operator of the derived class.
|
| 8 |
|
| 9 |
Any assignment operator, even the copy and move assignment operators,
|
| 10 |
+
can be virtual.
|
| 11 |
+
|
| 12 |
+
[*Note 1*:
|
| 13 |
+
|
| 14 |
+
For a derived class `D` with a base class `B` for which a virtual
|
| 15 |
+
copy/move assignment has been declared, the copy/move assignment
|
| 16 |
+
operator in `D` does not override `B`’s virtual copy/move assignment
|
| 17 |
+
operator.
|
| 18 |
+
|
| 19 |
+
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
struct B {
|
| 23 |
virtual int operator= (int);
|
| 24 |
virtual B& operator= (const B&);
|
|
|
|
| 34 |
void f() {
|
| 35 |
bptr->operator=(99); // calls D::operator=(int)
|
| 36 |
*bptr = 99; // ditto
|
| 37 |
bptr->operator=(dobj2); // calls D::operator=(const B&)
|
| 38 |
*bptr = dobj2; // ditto
|
| 39 |
+
dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)
|
|
|
|
| 40 |
}
|
| 41 |
```
|
| 42 |
|
| 43 |
+
— *end example*]
|
| 44 |
+
|
| 45 |
+
— *end note*]
|
| 46 |
+
|