Assignment operators
Template:cpp/language/sidebar Assignment operators modify the value of the object.
Operator name | Syntax | Overloadable | Prototype examples (for Template:cpp) | |
---|---|---|---|---|
Inside class definition | Outside class definition | |||
basic assignment | a = b
|
Yes | Template:cpp | N/A |
move assignment Template:mark c++0x | a = rvalue
|
Yes | Template:cpp | N/A |
addition assignment | a += b
|
Yes | Template:cpp | Template:cpp |
subtraction assignment | a -= b
|
Yes | Template:cpp | Template:cpp |
multiplication assignment | a *= b
|
Yes | Template:cpp | Template:cpp |
division assignment | a /= b
|
Yes | Template:cpp | Template:cpp |
modulo assignment | a %= b
|
Yes | Template:cpp | Template:cpp |
bitwise AND assignment | a &= b
|
Yes | Template:cpp | Template:cpp |
bitwise OR assignment | a |= b
|
Yes | Template:cpp | Template:cpp |
bitwise XOR assignment | a ^= b
|
Yes | Template:cpp | Template:cpp |
bitwise left shift assignment | a <<= b
|
Yes | Template:cpp | Template:cpp |
bitwise right shift assignment | a >>= b
|
Yes | Template:cpp | Template:cpp |
|
Explanation
basic assignment operator replaces the contents of the object a
with those of b
move assignment operator replaces the contents of the object a
with those of b
while minimizing copying overhead (no deep copy is performed). It complements the basic assignment operator.
Other assignment operators modify the contents of the object. Usually they are overloaded in classed performing mathematical operations.
See also
Common operators | ||||||
---|---|---|---|---|---|---|
assignment | increment decrement |
arithmetic | logical | comparison | member access |
other |
a = b |
++a |
+a |
!a |
a == b |
a[...] |
function call |
a(...) | ||||||
comma | ||||||
a, b | ||||||
conditional | ||||||
a ? b : c | ||||||
Special operators | ||||||
static_cast converts one type to another related type |