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

Denton Cockburn diboss at hotmail.com
Mon Feb 18 05:39:58 PST 2008


On Mon, 18 Feb 2008 19:36:31 +1100, Derek Parnell wrote:

> On Mon, 18 Feb 2008 07:12:08 +0000, Janice Caron wrote:
> 
>> I say again, there is no way to express "mutable reference to const
>> data" in D
> 
> Of course you can. I do it all the time. But maybe I don't understand what
> you are saying ;-)
> 
> import std.stdio;
> class Foo
> {
>     const string _me;
>     this(string name) { _me = name; writefln("Creating %s", _me); }    
> }
> void main()
> {
>    const(Foo) f;  // A mutable reference to const data.
> 
>    const(Foo) a = new Foo("one");
>    const(Foo) b = new Foo("two");
>    const(Foo) c = new Foo("three");
>    
>    f = a;
>    f = b;
>    f = c;
>    
>    writefln("%s", f._me);
>    
> }
> 

That doesn't compile in 2.010




More information about the Digitalmars-d mailing list