Move Constructor

Learned in CS247 - Software Engineering Principles.

A move constructor is used for when the object is constructed 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 situation where you want to efficiently transfer ownership of resources from one object to another without unnecessary copying.

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! I get confused really easily.