Extended Type Design.

jovo jovo at at.home
Mon Mar 19 11:03:59 PDT 2007


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?

jovo




More information about the Digitalmars-d mailing list