The problem with const (and a solution)

Sönke Ludwig ludwig at informatik_dot_uni-luebeck.de
Fri Dec 7 08:48:30 PST 2007


Steven Schveighoffer wrote:
> const(*C)* c;
> 

This would be a workable solution. Of course not pretty, but workable.

> C& c; // reference to a C class
> S& s; // reference to a S struct

I like the idea of unifying the different type classes.
However, as far as I understand it, the semantics of structs and classes will 
still be different with this syntax. This may be a potential source of bugs, 
especially for people coming from C++:

// struct references
S a = S(1);
S& b = a;
a = S(2);
assert( b == a );

// class references
C a = new C(1);
C& b = a;
a = new C(2);
assert( b == a ); // fails

// .. same as
C a = new C(1);
C b = a;
a = new C(2);



More information about the Digitalmars-d mailing list