Move Constructors - C++11
A move constructor in class C defines move semantics of C-objects
A move constructor takes an Rvalue references as parameter
- Giving away details of an object instead of copying the details - "destructive read"
- A move constructor C(C&& a) moves a into the current object
- The object a must be left in a state that the destructor can deal with (cheaply).
- A move constructor does not allocate resources - and should not throw any exception
- In constrast to a copy constructor
- The compiler can - in some situations - decide to use a move constructor instead of a copy constructor
- Alternatively, the programmer can enforce a move by casting to an Rvalue reference - using the move function.
- If moving should take place, and if no move function constructor exist, use the copy constructor (and pay the price).