Search⌘ K

Named Variables and rvalues

Explore the concept of named variables and rvalues in C++ to understand when the compiler moves objects rather than copying them. This lesson covers move semantics using std::move, distinctions between lvalues and rvalues, and practical examples with class member variables to help you write more efficient code.

We'll cover the following...

Concept of named variables and rvalues

So, when is the compiler allowed to move objects instead of copying? As a short answer, the compiler moves an object when the object can be categorized as an rvalue. The term rvalue might sound complicated, but in essence, it is just an object that is not tied to a named variable for either of the following reasons:

  • It's coming straight out of a function

  • We make a variable ...