Static operator overloads (again)

Denis Koroskin 2korden at gmail.com
Thu Sep 4 03:08:27 PDT 2008


On Thu, 04 Sep 2008 13:47:20 +0400, Giles Bathgate  
<gilesbathgate at gmail.com> wrote:

> Christopher Wright Wrote:
>
>> On the other hand, what about subclasses? They can't override the
>> behavior of an operator overload, if operator overloading uses static
>> methods. You're reduced to writing your overloads as:
>>
>> class Foo
>> {
>> 	static Foo opAddAssign (Foo left, Foo right)
>> 	{
>> 		return left.addAssign(right);
>> 	}
>> }
>>
>
> I don't understand your example. It was my understanding that static  
> methods cannot be overridden. (there is no vtable entry for a static  
> method)
>

Indeed, static methods can't be overriden. That's why you end up writing  
something like this to get polymorphism in C#.

> Maybe you thought that I an requesting for D's implementation of  
> operator overloads to ONLY use static methods?

No, but what is the real difference between two, apart from ability to  
pass null pointers which is a bad design anyway? It is redundant. I think  
it should be removed from language at all.



More information about the Digitalmars-d mailing list