delegate cannot handle polymorphism?

Nub Public nubpublic at gmail.com
Mon Jun 27 00:30:09 PDT 2011


class B
{
	void fun() { writeln("B"); }
}

class D : B
{
	override void fun() { writeln("D"); }
}

void delegate() dg = &b.fun;
dg.ptr = cast(void*)d;
dg();


Compiler: DMD 2.053
It prints "B" instead of "D".
The equivalent code in C++ prints "D" nicely.

Is it a bug or by design? I hope it's a bug coz it's smarter and more 
useful for delegates to handle polymorphism IMHO.


More information about the Digitalmars-d mailing list