Why can't we define re-assignable const reference variable?

Steven Schveighoffer schveiguy at yahoo.com
Wed Feb 20 13:25:43 PST 2008


"Sergey Gromov" wrote
> Steven Schveighoffer wrote:
>> > The traditional usage of parentheses is this: foo(x).  This means that 
>> > a
>> > function foo is applied to its argument x, and not applied to 
>> > everything
>> > else.  You are probably talking about some different tradition.  Please
>> > clarify.
>>
>> That is the usage I am referring to.  I'll spell it out in English:
>>
>> class C means that C is equivalent to a "reference to a some data" that
>> compromises the class that follows the given definition.

Arghh! I can't type today!  Compromises? :)

>
> At least, now I understand why we can't understand each other.
>
> For a declaration,
>
> C x;
>
> you imply reference in C, and I imply reference in x.
>
> const(C) x;   // text written
> const(C) (ref x); // my understanding
> const(C ref) x; // your understanding
>
> No wonder we can't agree.  Now I'm curious why the difference.  To me, C
> is a class, and x is a reference.  Why it's different for you ?

C is a class reference.  There is no way to express the type of the class 
data, because D doesn't support value-type classes.  I.e. there is no way to 
separate the reference from C.  Whenever you see:

class C {}

in D, It's like the equivalent in C++ of

class _C {};
typedef _C& C;

But in D there is no way to get at the type _C.  And D class references are 
rebindable.

In D, the type never is in the variable, it's always in the type 
declaration.

-Steve 





More information about the Digitalmars-d mailing list