Member function pointers

d coder via Digitalmars-d digitalmars-d at puremagic.com
Tue May 27 02:58:36 PDT 2014


On Mon, Jun 10, 2013 at 10:13 PM, Jacob Carlborg <doob at me.com> wrote:

> On 2013-06-10 18:34, Manu wrote:
>
>> On 11 June 2013 02:26, Jacob Carlborg <doob at me.com <mailto:doob at me.com>>
>>
>> wrote:
>>
>>     On 2013-06-10 17:40, David Nadlinger wrote:
>>
>>         Let me try to summarize it in code:
>>
>>         ---
>>         class A { void foo(); }
>>         auto memberFun = (&A.foo).funcptr;
>>
>>         auto a = new A;
>>         memberFun(a);
>>         ---
>>
>>
>>     Why is this better than a delegate?
>>
>>
>> It's not 'better', it's different.
>>
>
> class A { void foo(); }
> auto memberFun = (&A.foo).funcptr;
>
> auto a = new A;
> void delegate () dg;
> dg.funcptr = memberFun;
> dg.ptr = cast(void*) a;
> dg();
>
> The details can be hidden in a function call. Sure, a delegate could be
> type safe but still don't see the point.
>
> --
> /Jacob Carlborg
>

Greetings

Apologies for bringing up this year old thread.

With https://github.com/D-Programming-Language/dmd/pull/3181 getting
merged, it is no longer feasible to directly assign dg.funcptr (which is
not an lvalue now). The problem is that the code suggested by David also
does not work.

Is there an alternative?

Regards
- Puneet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140527/734eb0bf/attachment.html>


More information about the Digitalmars-d mailing list