From Jason Turner

[over.assign]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpkprqb4yk/{from.md → to.md} +52 -0
tmp/tmpkprqb4yk/{from.md → to.md} RENAMED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Simple assignment <a id="over.assign">[[over.assign]]</a>
2
+
3
+ A *simple assignment operator function* is a binary operator function
4
+ named `operator=`. A simple assignment operator function shall be a
5
+ non-static member function.
6
+
7
+ [*Note 1*: Because only standard conversion sequences are considered
8
+ when converting to the left operand of an assignment operation
9
+ [[over.best.ics]], an expression `x = y` with a subexpression x of class
10
+ type is always interpreted as `x.operator=(y)`. — *end note*]
11
+
12
+ [*Note 2*: Since a copy assignment operator is implicitly declared for
13
+ a class if not declared by the user [[class.copy.assign]], a base class
14
+ assignment operator function is always hidden by the copy assignment
15
+ operator function of the derived class. — *end note*]
16
+
17
+ [*Note 3*:
18
+
19
+ Any assignment operator function, even the copy and move assignment
20
+ operators, can be virtual. For a derived class `D` with a base class `B`
21
+ for which a virtual copy/move assignment has been declared, the
22
+ copy/move assignment operator in `D` does not override `B`’s virtual
23
+ copy/move assignment operator.
24
+
25
+ [*Example 1*:
26
+
27
+ ``` cpp
28
+ struct B {
29
+ virtual int operator= (int);
30
+ virtual B& operator= (const B&);
31
+ };
32
+ struct D : B {
33
+ virtual int operator= (int);
34
+ virtual D& operator= (const B&);
35
+ };
36
+
37
+ D dobj1;
38
+ D dobj2;
39
+ B* bptr = &dobj1;
40
+ void f() {
41
+ bptr->operator=(99); // calls D::operator=(int)
42
+ *bptr = 99; // ditto
43
+ bptr->operator=(dobj2); // calls D::operator=(const B&)
44
+ *bptr = dobj2; // ditto
45
+ dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)
46
+ }
47
+ ```
48
+
49
+ — *end example*]
50
+
51
+ — *end note*]
52
+