Content deleted Content added
GloryRoad66 (talk | contribs) Added tags to the page using Page Curation (stub, uncategorised) |
Monospace |
||
(32 intermediate revisions by 25 users not shown) | |||
Line 1:
{{Short description|Operator used in C++}}
In the [[C++|C++ programming language]], the '''move assignment operator'''
If the move assignment operator is not explicitly defined,
== Overloading move assignment operator ==
To overload the move assignment operator, the signature of the function must be
T& operator=(T&& data)
</syntaxhighlight>To successfully overload the move assignment operator, the following conditions must be met:
Line 12 ⟶ 11:
* The current object's data is de-allocated.
* The object that is being moved from must have its data marked as [[nullptr]] (or something to signify the move)
* The operator
public:▼
Resource& operator=(Resource&& other) {▼
delete this->data; // Delete the object's data▼
this->data = other.data; // "Move" other's data into the current object▼
other.data = nullptr; // Mark the other object as "empty"▼
class String {
▲ public:
// If we're not trying to move the object into itself...
▲
return *this;▼
}
private:
};
</syntaxhighlight>
==References==
<references />
{{C++ programming language}}
[[Category:C++]]
[[Category:Operators (programming)]]
[[Category:Assignment operations]]
{{compu-prog-stub}}
|