D: Overriding opDispatch in subclass

d, inheritance, opdispatch, overriding

Solution

Member template functions cannot be virtual and hence cannot be overridden.

http://dlang.org/function.html#virtual-functions

opDispatch is templated function. These two calls are identical:

s.callingOpDispatch();
s.opDispatch!("callingOpDispatch")()

Problem

Is there any way to override opDispatch in a subclass? What I actually want to do is to pass around a variable with the superclass as its static type, but which redirects calls to opDispatch to its sub-type (the dynamic type). Basically, I want this code to print "Sub" instead of "Super". ``` import std.stdio; class Super { void opDispatch(string m)() { writeln("Super"); } } class Sub : Super { override void opDispatch(string m)() { writeln("Sub"); } } void main() { Super s = new Sub(); s.callingOpDispatch; // Writes "Super" instead of "Sub" } ``` I'm dumbfounded, as I cannot force the compiler to look for method overrides by using abstract methods (D doesn't allow abstract templated methods). PS: Could someone please create the tag opDispatch? (It seems to me that it would be good for D?)

Original source