Big Five

Move Constructor

Seen in CS247.

A move constructor is used for when the object is contructed with an rvalue.

Definition

Node::Node(Node&& other): data{other.data}, next {other.next} {
	other.next = nullptr;
}

Usage

Node alphabet{getAlphabet()}; // Move ctor
 
// Another case
Node a;
Node b{std::move(a)}; // move ctor

when would you ever use Move / Move Assignment Operator?

Move operations are primarily used in situations where you want to efficiently transfer ownership of resources from one object to another without unnecessary copying.

However, most of the time, if you are thinking about the move constructor, you are wrong. It’s likely the Copy Constructor or Copy Assignment Operator. Don’t get confused so easily.