overiding mutable methods in immutable classes

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 22 09:06:28 PST 2014


On Saturday, 22 November 2014 at 15:00:00 UTC, Eric wrote:
> Yes, but if I don't declare the class T as immutable, I don't
> think this constraint will work.

You're mistaken. It works just fine.

class X /* not immutable */
{
      private int x;
      this(int x) pure { this.x = x; }
}
template foo(T : immutable Object)
{
      void foo(T thing) {}
}
void main()
{
       foo(new immutable X(5));
}


More information about the Digitalmars-d-learn mailing list