encyclopegia.org

Move assignment operator

In the C++ programming language, the move assignment operator = is used for transferring a temporary object to an existing object. The move assignment operator, like most C++ operators, can be overloaded. Like the copy assignment operator it is a special member function. If the move assignment operator is not explicitly defined, the compiler generates an implicit move assignment operator (C++11 and newer) provided that copy/move constructors, copy assignment operator or destructors have not been declared. The parameter of a move assignment operator is an rvalue reference ( T&& ) to type T , where T is the object that defines the move assignment operator. The move assignment operator is different than a move constructor because a move assignment operator is called on an existing object, while a move constructor is called on an object created by the operation. Thereafter, the other object's data is no longer valid.

In the C++ programming language, the move assignment operator = is used for transferring a temporary object to an existing object. The move assignment operator, like most C++ operators, can be overloaded. Like the copy assignment operator it is a special member function. If the move assignment operator is not explicitly defined, the compiler generates an implicit move assignment operator (C++11 and newer) provided that copy/move constructors, copy assignment operator or destructors have not been declared. The parameter of a move assignment operator is an rvalue reference ( T&& ) to type T , where T is the object that defines the move assignment operator. The move assignment operator is different than a move constructor because a move assignment operator is called on an existing object, while a move constructor is called on an object created by the operation. Thereafter, the other object's data is no longer valid. T& operator=(T&& data); To successfully overload the move assignment operator, the following conditions must be met: Check if the object calling the operator is not calling the operator on itself. 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 must return a reference to *this . Consider the following move assignment operator for a simple string class: class MyString { private: char* data_; public: MyString& operator=(MyString&& other) noexcept { // If we're not trying to move the object into itself... if (this != &other) { delete[] this->data; // Free this string's original data. this->data = other.data; // Copy the other string's data pointer into this string. other.data = nullptr; // Finally, reset the other string's data pointer. } return *this; } }; ==References==

References

No reference rows published for this article.

Cite this article

MLA

"Move assignment operator." encyclopegia.org, 2026, https://encyclopegia.org/wiki/move-assignment-operator. Accessed 24 November 2026.

Chicago

"Move assignment operator." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/move-assignment-operator.

APA

encyclopegia.org. (2026). Move assignment operator. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/move-assignment-operator

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

tour operator

stub · references available

dance move

stub · references available

Prewitt operator

stub · references available

Hello Operator

stub · references available

move

stub · references available

Assignment Berlin

stub · references available

Invariant differential operator

stub · references available

Police Academy 5: Assignment Miami Beach

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1352217401 · 0.5 · snapshot enwiki-001352217401

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.