Why can't we define re-assignable const reference variable?
Robert Fraser
fraserofthenight at gmail.coim
Sun Feb 17 11:13:37 PST 2008
Janice Caron Wrote:
> On 17/02/2008, Robert Fraser <fraserofthenight at gmail.coim> wrote:
> > s1 = s2; // Okay
> > c1 = c2; // Okay
> > s1.x = 5; // Not okay
> > c1.x = 5; // Not okay
> >
> > When I proposed this, NOBODY agreed with me (that is, everybody who responded wanted structs/classes to act differently for generic programming purposes).
>
> Isn't that rather because modifying s1.x modifies s1?
Technically, yes. But what I was (and still am) campaigning for is syntax changes where by "struct S" can be changed to "class X" and no client code will be broken at all. Structs/classes should behave differently from an implementation perspective (not like C++), so for example structs are data types/stack allocated and don't support inheritance, but they should be usable in roughly the same way by clients. This removes the decision from the API for most purposes.
More information about the Digitalmars-d
mailing list