I'm on the last appendix of C++ primer 5th edition. (Solution part):
Here is an example from there:
Assume
Yis a class that defines its own copy-constructor but not a move-constructorstruct hasY{ hasY() = default; hasY(hasY&&) = default; Y mem; // hasY will have a deleted move constructor }; hasY hy, hy2 = std::move(hy); // error: move constructor is deleted
I've added the definition of struct Y:
struct Y{
Y() = default;
Y(Y const&){cout << "Y's cpy-ctor\n";}
};
When I run the program, it works just fine and doesn't complain about the
hasY's deleted move constructor. And I get the output:Y's cpy-ctorSo I think this works because objects of type
Yare moved through the copy-constructor but not the reverse. So calling thehasY's move-ctor invokesY's move-ctor which is deleted then the compiler usesY's copy-ctor to move that element. Am I right? guide me. Thank you!