Extended Type Design.

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Mon Mar 19 12:14:08 PDT 2007


jovo wrote:
> James Dennett Wrote:
>> "final", I think, is a workaround for handling types
>> that are accessed through automatically-dereferenced
>> GC'd pointers in D.  The auto-deref property hides the
>> actual type of those pointers from us, so we can't const-
>> qualify them; we just end up adding const to the type to
>> which they point.  C++ doesn't work this way, and so
>> const does everything that final does and more in C++.
>> It's just different.  If you want indirection via a
>> reference/pointer, C++ makes you say so, but gives you
>> the chance to apply type modifiers to that pointer.  D
>> does it invisibly, but then requires extra syntax to be
>> able to stop the name being rebindable.
>>
> 
> But I think it is'nt key point here. As I understand, const
> will afect all from the specified stage in the reference chain,
> unlike C++ const?
> 
> Code analogous to this legal C++ code will be compile time error?
> 
> struct S { int *x; };
>     
> int a = 12;
> S s = { &a };
> const S *p = &s;
> *p->x = 20;  // will be error?

Yes. D's const is transitive.

Andrei



More information about the Digitalmars-d mailing list