how to fix such a hijacking problem in D ?

z_axis z_axis at 163.com
Sun Dec 16 03:51:00 PST 2007


import std.stdio;

class A
{
     void foo(long) {}
     void def() { writefln("A.def()"); foo(1L); }  // expects to call  
A.foo(long)
}

class B : A
{
     void foo(long) { writefln("B.foo()"); };	// will hijack A's foo()
}

void abc(B b)
{	
     b.def();
}


void main(char[][] args)
{	
    abc(new B);
}
output:
A.def()
B.foo()

The B will hijack the A's foo(long) ?!

any suggestion ?


More information about the Digitalmars-d-learn mailing list