Extended Type Design.
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Wed Mar 21 11:51:07 PDT 2007
Tyler Knott wrote:
> Bruno Medeiros wrote:
>>
>> What?? If f is 'const', how are any of those "f.s =" assignments allowed?
>>
>
> Because f is a POD (Plain Old Data) structure and not a reference you
> can modify the data in the structure, but because it's declared const
> you can't modify any data referenced. If you want f.s to be
> unassignable then declare f to be final Foo, though you can then modify
> the data referenced by f.s so f.s[0] = 'a'; becomes legal.
>
> For example:
>
> struct Foo
> {
> char[] s = "hello";
> char c;
> }
>
Duh, of course. I misread and was thinking Foo was a class and not a struct.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list