A fresh look at comparisons

Janice Caron caron800 at googlemail.com
Wed Apr 16 09:35:46 PDT 2008


On 16/04/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  I don't think D should limit opCmp to be non virtual. That
>  should be decided by the programmer (if needed the programmer can use
>  "final").

It would be a very bad thing indeed for anyone to make opCmp()
non-virtual, aka final.

I have suggested something completely different. I have suggested that
if comparison is defined for class A, but not for class B which is a
subclass of A, then by default, objects of type B shall be considered
incomparable.

That is absolutely /not/ the same thing as implementing final opCmp()
in A. All final would do is block polymorphism (which would be worse,
actually, since that would actually /prevent/ B's opCmp() from being
used in some situations). It wouldn't stop b < c from calling
A.opCmp().

final stops derived class functions from being called, which is the
wrong direction. I propose the opposite - that base class functions
not be called. There is currently no mechanism in D which allows one
to specify that.



More information about the Digitalmars-d mailing list