There are two potential locations in your code where you can expect the move constructor to be called (but it is not):
1) call std :: move
2) at the time of appointment.
As for 1), std :: move makes a simple actor - it does not create an object from a copy - if it were possible, the move constructor could be called by it, but since it performs a simple rvalue cast, t is called. The definition of std :: move is similar to static_cast<Event&&>(temp) .
As for 2), initialization and purpose are two completely different operations (although the "=" symbol is used in some forms of initialization). Your code performs the assignment and therefore uses the default assignment operator, which is declared to accept a reference to the lvalue constant. Since you never initialize one event object to another, you will not see that your move constructor is called. If you declared a forwarding assignment operator: Event& operator=(Event&& other) , then your current code will call it or if you wrote: Event a; Event tmp = move(a); Event a; Event tmp = move(a); your move constructor, as written, will be called.
source share