#include <iostream>
class Class
{
public:
Class() { std::cerr << "ctor" << std::endl; }
~Class() { std::cerr <<"dtor" << std::endl; }
Class(Class&) { std::cerr << "copy ctor" << std::endl; }
Class & operator=(const Class &)
{
std::cerr << "copy operator=" << std::endl;
return *this;
}
Class(Class&&) { std::cerr << "move ctor" << std::endl;}
Class & operator=(Class &&)
{
std::cerr << "move operator="<< std::endl;
return *this;
}
};
int main(int, char**)
{
Class object;
Class && rvr = Class();
object = rvr; // (*)
}
Output is
ctor
ctor
copy operator=
dtor
dtor
1) Why "copy ctor" is called at line (*)?
2) If i have to use std::move() every-time, what is the difference between "move semantics" and any method that will move data, like object.destructive_move();
?
3) when exactly move ctor/operator is called?
thanks!