Why is = default on operator = compiled when there is a const member?

class Foo { public: Foo& operator=(const Foo&) = default; private: const int i = 0; }; 

Why is =default allowed? It compiles without errors. I think that =default should fail, since it is not possible to assign const to a variable?

What is really going on?

+6
source share
1 answer

If the function cannot be generated (as is the case), = default will generate it as = delete d. If you try to use this assignment operator, your compiler should produce an error .

+13
source

All Articles