Help - can't ADD constness

Bruce Adams tortoise_74 at yeah.who.co.uk
Sun Sep 16 13:11:35 PDT 2007


Robert Fraser Wrote:

> Janice Caron Wrote:
> 
> > This won't compile under D2.004
> > 
> >  class A
> >  {
> >      int x;
> >  }
> > 
> >  void main()
> >  {
> >      const a = new A(); /* Error */
> >  }
> > 
> > The error is
> > Error: non-constant expression cast(const A)new A
> > 
> > Now what's going on here? Are we not allowed to turn mutables into consts now?
> 
> You're using the const storage class, which means compile-time constant. Try:
> 
> const(A) = new A();

Doh! That explains a lot of problems I was having a while back (I basically ended up not using const at all).
That really is quite sucky and counter intuitive. How on earth did that idea get off the drawing board? 
Someone ought to start a thread about replacing it with something better. Oh wait, they already did :).



More information about the Digitalmars-d mailing list