An implicitly generated statement recursively assigns each non-static member. However, x is const , so it cannot be assigned. This prevents the creation of an implicit statement (in particular, it defines it as remote).
This is stated in C ++ 11 12.8 / 23:
The default assignment operator for copy / move by default for class X is defined as remote if X has:
- ...
- non-static data member of type const non-class (or its array) or
- ...
(Although I just noticed that your compiler precedes C ++ 11, the rules are similar, but are specified in different languages, in old dialects without the concept of "remote" functions).
If you need an assignment operator for a class whose members (or base classes) cannot be reassigned, you will have to define it yourself.
In class A constant member is static, so it is not part of the object. Therefore, this does not prevent the assignment of an (empty) object.
source share