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),
= defaultwill generate it as= deleted instead. If you try to use that assignment operator your compiler should produce an error.