Member function pointers

Manu turkeyman at gmail.com
Mon Jun 10 06:47:18 PDT 2013


On 10 June 2013 22:56, Jacob Carlborg <doob at me.com> wrote:

> On 2013-06-10 14:32, Michel Fortin wrote:
>
>  Type-safety. I mean, you can do this if you want:
>>
>>      auto funcptr = &Object.toString;
>>      auto object = new Object;
>>
>>      // now call our function using object
>>      string delegate() deleg;
>>      deleg.ptr = cast(void*)object;
>>      deleg.funcptr = funcptr;
>>
>> but this is not type-safe: the funcptr type ("string function()") is
>> actually wrong (it'll only work if called from a delegate) and the
>> object pointer the in the delegate is a void*. All Manu is asking is
>> that funcptr is of a correct type so you can call it directly by
>> supplying "this" as an argument, like this:
>>
>>      funcptr(object);
>>
>> The problem is that this "correct type" for the function pointer does
>> not exist currently. Calling a member function uses a different ABI, so
>> the type needs to know somehow its a pointer to a member function (and
>> that its first parameter is "this"), otherwise the generated code at the
>> call site will be all wrong.
>>
>
> Then he's asking for (more) type safe delegates and support for C++ member
> function pointers.


I'm really not asking for delegates (although they could become more
typesafe given my suggestion), just a member function pointer. And not C++
style as you say, my suggestion is much simpler than that, and would fit
nicely in D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130610/5c29bc40/attachment.html>


More information about the Digitalmars-d mailing list