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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With