The Status of Const

Pelle pelle.mansson at gmail.com
Tue Aug 17 03:05:55 PDT 2010


On 08/17/2010 01:44 AM, Steven Schveighoffer wrote:
> On Mon, 16 Aug 2010 19:06:56 -0400, Simen kjaeraas
> <simen.kjaras at gmail.com> wrote:
>> Uhm, it works in D:
>>
>> class C {}
>> class D : C {}
>>
>> void main( ) {
>> D[] a;
>> C[] b = a;
>> }
>
> Yes, I was about to say that except that is a bug kind of. The type
> system should only allow casting D[] to const(C)[].

class C { }
class D : C { }
class E : C { }

void append_to(ref const(C)[] cs, const(C) c) { cs ~= c; }

D[] ds;
append_to(ds, new E);


*ahem*
D[] can not be converted to const(C). That it works today is pretty 
terrible. Rewrite the append_to to work with Objects, and well. :-)


More information about the Digitalmars-d mailing list