Should operator overload methods be virtual?

dsimcha dsimcha at yahoo.com
Fri Nov 27 20:44:38 PST 2009


== Quote from retard (re at tard.com.invalid)'s article
> Fri, 27 Nov 2009 15:32:21 -0800, Walter Bright wrote:
> > Making them not virtual would also make them not overridable, they'd all
> > be implicitly final.
> >
> > Is there any compelling use case for virtual operator overloads? Keep in
> > mind that any non-virtual function can still be a wrapper for another
> > virtual method, so it is still possible (with a bit of extra work) for a
> > class to have virtual operator overloads. It just wouldn't be the
> > default.
> Is this again one of those features that is supposed to hide the fact
> that dmd & optlink toolchain sucks? At least gcc can optimize the calls
> in most cases where the operator is defined to be virtual, but is used in
> non-polymorphic manner.

If so, I think it's a bad idea.

1.  Eventually, we will get a better optimizer.  GDC has been resurrected, and
after D2 is finalized and all of the more severe bugs are fixed, hopefully Walter
will have some time to focus on performance issues.

2.  This optimization can trivially be done manually by declaring the overloads
final.  What would we gain by introducing the inconsistency with "normal" methods?



More information about the Digitalmars-d mailing list