Should operator overload methods be virtual?

Robert Jacques sandford at jhu.edu
Fri Nov 27 22:41:16 PST 2009


On Fri, 27 Nov 2009 22:58:00 -0500, retard <re at tard.com.invalid> wrote:

> 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.

Yes and no. Yes, DMD doesn't have link time optimization (LTO), which is  
what enables this. No, because LTO can't do this optimization in many  
cases, such as creating/using a DLL/shared object. (Static libraries might  
also have some issues, but I'm not sure.)



More information about the Digitalmars-d mailing list