Static operator overloads (again)
Christopher Wright
dhasenan at gmail.com
Thu Sep 4 17:55:53 PDT 2008
Giles Bathgate 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)
That is my point. Static methods cannot be overridden. I want virtual
operator overloads.
> Maybe you thought that I an requesting for D's implementation of operator overloads to ONLY use static methods?
So your suggestion is to convert:
{{{
MyClass instance1, instance2;
auto instance3 = instance1 + instance2;
}}}
to:
{{{
MyClass instance1, instance2;
MyClass instance3;
static if (isStaticMethod!(MyClass.opAdd))
instance3 = MyClass.opAdd(instance1, instance2);
else
instance3 = instance1.opAdd(instance2);
}}}
I don't see anything wrong with this suggestion. But I just don't see
any compelling reason for it. I'm not getting off my chair to patch dmd
to support this.
More information about the Digitalmars-d
mailing list