class Foo {
public:
Foo& operator=(const Foo&) = default;
private:
const int i = 0;
};
Why is =default
allowed there? It compiles without errors. I would think that =default
should fail since it's not possibly to assign into the const
variable?
What actually is happening?
When the function cannot be generated (as is the case), = default
will generate it as = delete
d instead. If you try to use that assignment operator your compiler should produce an error.
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