On 05/03/2012 09:01 PM, Gor Gyolchanyan wrote:
class B: A
{
     void foo()
     {
         writeln("B.foo called");
     }
}

void main()
{
    auto a = new A();
    auto fn =&a.foo;
    auto ptr = fn.funcptr;
    auto b = new B();
    (cast(void function(A))ptr)(b);
}

will this work?


It should work (at least) with the D calling convention, yes.

A somewhat more portable way would probably be:

auto fn = &a.foo;
fn.ptr = cast(void*)b;
fn();

Reply via email to