virtual method pointer
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Thu May 3 12:18:25 PDT 2012
So, you're saying, that the foo function actually takes the *this,
which we ass manually, extracts the real foo method and calls it?
AFAIK, that shouldn't be the case. The delegate extracts the A's foo
and call to the delegate should be a direct call to A.foo, not a
virtual call.
On Thu, May 3, 2012 at 11:11 PM, Timon Gehr <timon.gehr at gmx.ch> wrote:
> 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();
--
Bye,
Gor Gyolchanyan.
More information about the Digitalmars-d
mailing list