how to fix such a hijacking problem in D ?
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Dec 16 05:21:36 PST 2007
"z_axis" <z_axis at 163.com> wrote in message news:op.t3fe7a2l1uofcn at sw2wolf...
> import std.stdio;
>
> class A
> {
> void foo(long) {}
> void def() { writefln("A.def()"); foo(1L); } // expects to call
> A.foo(long)
> }
Another way to solve this (Bill's will probably work too) is to make the
call to foo non-virtual.
void def()
{
writefln("A.def()");
typeof(this).foo(1L); // performs non-virtual call
}
This way foo can still be virtual and overridden, but the call will always
call A's implementation of foo.
More information about the Digitalmars-d-learn
mailing list