I got into a situation that is quite interesting as the code that I work on compilers, although I am surprised that this is so, I would like to ask you about your reception.
The situation is as follows. I have a class with remote move and copy constructs that have custom assignment operators:
struct A { A() { } A(const A&) = delete; A(A&& ) = delete; A& operator=(const A& ) { return *this; } A& operator=(A&& ) { return *this; } };
And I have another class with A as a single member. In this class, I defined the copy constructor, but I saved the default move constructor and defined the assignment operator by calling the swap function:
class B{ public: A a; B() : a{} { } B(const B&) : a{} { } B(B&& other) = default; }; int main() { B b1; B b2(std::move(b1));
Why does the default move constructor work, given that it cannot just call the move or copy constructor A? I am using gcc 4.8.4.
source share