Thread overview | |||||
---|---|---|---|---|---|
|
July 08, 2012 Portable way to obtain member function pointer (and invoke it)? | ||||
---|---|---|---|---|
| ||||
Hi,
Is there a portable way to obtain a pointer to a member function and invoke it with the this reference? I seem to recall some discussion about this on the NG in the past, but can't find the thread now.
--
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
|
July 08, 2012 Re: Portable way to obtain member function pointer (and invoke it)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On 07/08/2012 09:57 PM, Alex Rønne Petersen wrote:
> Hi,
>
> Is there a portable way to obtain a pointer to a member function and
> invoke it with the this reference? I seem to recall some discussion
> about this on the NG in the past, but can't find the thread now.
>
auto mptr = function(Base o,Args args)=>o.member(args);
mptr(this, args);
|
July 08, 2012 Re: Portable way to obtain member function pointer (and invoke it)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | Am 08.07.2012 21:57, schrieb Alex Rønne Petersen:
> Hi,
>
> Is there a portable way to obtain a pointer to a member function and
> invoke it with the this reference? I seem to recall some discussion
> about this on the NG in the past, but can't find the thread now.
>
If you know both at compile time:
auto func = &object.func;
This will create a delegate with the this pointer and the function pointer. If you want to build it manually you can do that also:
alias void delegate() func_t;
func_t func;
func.funcptr = GetFunctionPointer();
func.ptr = object;
Kind Regards
Benjamin Thaut
|
Copyright © 1999-2021 by the D Language Foundation