On Wednesday, 11 July 2012 at 18:21:24 UTC, Steven Schveighoffer wrote:
...
It also seems to allow abuses.  For example:

class A
{
   private int _x;
   public @property x() const { return _x; }
}

class B : A
{
   private int _x2;
   public @property x() { return _x2++; }
}

Now I've completely changed the logistics of the x property so that it's essentially become mutable. In effect, I overrode the const piece of x completely to make it non-const without a cast, and anyone calling x() on an A instance cannot trust that it won't increment the effective value of x().

I think the solution to this overall problem is simply to make object.opEquals use the most derived types available for comparison.

-Steve

I thought about this example. You can have a const method returning different values anyway (instead of returning what base class' method would return), and A._x has not been mutated. From my point of view, it is just a different concept, but arguably not a worse one.

Reply via email to