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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.