vtbl jamming
Kirk McDonald
kirklin.mcdonald at gmail.com
Mon Sep 10 03:20:58 PDT 2007
Vladimir Panteleev wrote:
> On Mon, 10 Sep 2007 09:40:59 +0300, BCS <ao at pathlink.com> wrote:
>
>
>> can we get some way to do this?
>>
>> http://www.artima.com/cppsource/backyard2.html
>
>
> Modifying VTBLs is effectively the same as using method pointers (as
> a static field). The advantage is when we don't have access to the
> base class. Of course, D doesn't have method pointers (like C++),
> so...
>
It sort of does. You can fake them with delegates:
class Foo {
void bar() { writefln("Foo.bar"); }
}
void ptr_call(void function() fn, Object o) {
void delegate() dg;
dg.ptr = o;
dg.funcptr = fn;
dg();
}
void main() {
auto f = new Foo;
void function() fn = &Foo.bar;
ptr_call(fn, f);
}
I write this without testing it, and may have left out a cast or two.
But the idea is sound. (Indeed, Pyd relies on it.)
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list