Why is the move constructor defined and the assignment operator implicitly deleted?

c++, c++11, g++, gcc

Solution

The answer is because the C++ standard says so:

[class.copy]

If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4).

You can always declare a default copy constructor, in your case:

 Foo(const Foo&) = default;

Problem

``` struct Foo { Foo() = default; Foo(Foo&&) = default; }; int main() { Foo a, b; a = b; // ^ return 0; } ``` error: use of deleted function 'Foo& Foo::operator=(const Foo&)' in g++4.6 -std=c++0x it's ok. but, in g++6.2 -std=c++11 it's error. why?

Original source

Related problems