...

/

Move Semantics Explained

Move Semantics Explained

Get introduced to move semantics and some important rules for handling resources inside a class.

Understanding Move Semantics

Move semantics is a concept introduced in C++11 that is quite hard to grasp, even by experienced programmers. Therefore, we will try to give you an in-depth explanation of how it works, when the compiler utilizes it, and, most importantly, why it is needed. Essentially, the reason C++ even has the concept of move semantics, whereas most other languages don’t, is a result of it being a value-based language, as discussed before. If C++ did not have move semantics built-in, the advantages of value-based semantics would get lost in many cases, and programmers would have to perform one of the following trade-offs:

  • Performing redundant deep-cloning operations with high-performance costs
  • Using pointers for objects like Java
...