how to do member function pointer in D?
Kirk McDonald
kirklin.mcdonald at gmail.com
Wed Jul 30 22:33:54 PDT 2008
u wrote:
>>I'm not sure I completely understand either but I'll take a stab. What
>>about using polymorphism? Where delegates can be any type of object
>>interfaces restrict what sort of objects can be used with your hash-table.
>
>
> Go back to my original question:
>
> How to create a variable which hold a particular function pointer of a class, and
> can be invoked on different objects of that class:
>
> fp = &(A.f);
> A a1, a2;
> a1.fp(); // how to make this invocation work?
> a2.fp();
>
> And I have one more requirement that even if A.f() and A.g() have same signature,
>
> fp = &(A.g); // expect compiler report error here.
>
> How to declare the type of such fp?
There is a current thread in digitalmars.D.learn titled "Pointer to
member variable again." It has turned into a discussion of this very topic.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list