www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Help - can't ADD constness

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 :).
Sep 16 2007