If the string in your example is std::string , itโs just the same: by default, a copy and forwarding of their respective members is provided. And std::string has a copy and moves both implemented, so that temporary moves move, variables are copied.
There is no need to define a specific copy and move ctor and assign. You can just leave the constructor
A::A(string s) :test(std::move(s)) {}
In general, a simple copy and move implementation may be as follows
class A { public: A() :p() {} A(const A& a) :p(new data(*ap)) {}
operator= takes a value that is internally moved. If it comes from a temporary move, if it comes from a variable, it is copied. The difference between copy and move requires different constructors, but if we get A as
class B: public A { ... };
there is no need to redefine anything, because by default copy-ctor for B calls a copy for A, and by default for B causes a move for A, and all the default assignment operators for B call the only one defined for A (which is moved or copied depending from what was redirected).
Emilio garavaglia
source share