I have some ambiguities about "move" semantics: What I've read is that a move constructor or assignment is defined implicitly as a deleted function if the class has defined one of its own copy-control members. But I have this code:
int main()
{
struct A {
A() = default;
A(const A&) { cout << "A's cpy-ctor\n"; } // this forces move ctor to be defined as a deleted function
//A(A&&) = default;
//A(A&&) = delete; // if uncomment this line then the line below calling std::move will cause an error(referencing a deleted function).
};
A a = std::move(A{}); // move not available then use copy-ctor instead
std::cout << "\ndone\n";
}
If I uncomment the first commented line then it is OK as I've guessed: the copy-constructor is used instead of the move-ctor as the fact it is not explicitly defined.
But if I uncomment the second commented line I'll get compile-time error on calling std::move complaining about a deleted function. But why the compiler doesn't use copy-ctor instead directly?
What does mean defulting this move-ctor and how does that affect function-matching?
Thank you so much!