Move assignment operator: Difference between revisions

Content deleted Content added
m Added reference
mNo edit summary
Line 1:
In the [[C++|C++ programming language]], the move assignment operator (=), is used for transferring ownership (moving) of an an already instantiated object or resource to another ___locationobject. The move assignment operator, like most of the other C++ operators, can be [[Operator overloading|overloaded]]. It is one the of the [[special member functions]].<ref>{{Cite journal|title = Special member functions|url = https://en.wikipedia.org/w/index.php?title=Special_member_functions&oldid=662581955|journal = Wikipedia, the free encyclopedia|language = en}}</ref>
 
If the move assignment operator is not explicitly defined, then the compiler will generate an implicit move assignment operator ([[C++11]] and newer). The parameters of a move assignment operator are an [[rvalue reference]] (T&&) to type ''T, where''; ''T'' isbeing the typeobject that defines the move assignment operator is called on, or any overloaded type. The move assignment operator is different than a [[move constructor]] because a move assignment operator is called on an existing object, as a move constructor would be called on an object being created. One must somehow also signify the other object's data is not valid anymore, and has been moved.
 
__FORCETOC__
Line 11:
* 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 returns a reference to "*this".