const attribute makes whole element const?
Timon Gehr
timon.gehr at gmx.ch
Sun Sep 9 18:26:41 PDT 2012
On 09/10/2012 02:05 AM, Namespace wrote:
> I had never problems with that in C++.
clang++ sez:
error: cannot define the implicit default assignment operator for 'S',
because non-static const member 'x' can't use default assignment operator
> If I have members which are const because they are assigned only one
> time and needs no other assignment, why should I declare this member not
> as const?
>
You can, but then you have to provide your own assignment operator and
you have to work around the aforementioned bug that implies the
assignment operator is not invoked for associative array index
assignments.
> In the example I know exactly that I assign only one time a name to this
> struct, so why I should not declare it as const?
>
> Other example: you have a unique birthday date. This is const you cannot
> change it like a name or a telephone number.
Therefore I cannot be default-assigned to.
More information about the Digitalmars-d-learn
mailing list