Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I did some research here on function pointers
on class member functions, it seems if one
wants to use function pointers to class member
functions, we can't avoid wrapper methods right?
(i.e., who embed the actual function we want to call through function pointers).
Posted

1 solution

Your research was not very thorough then. Of course you can call a member function via a member function pointer without using a static wrapper. You just have to use the correct syntax and apply the call to an object of the corresponding type. So you have to keep two things around:

- the object pointer
- the member function pointer

Many people try to combine both things into what is called a Delegate. If you search under this keyword, you will find a great many CodeProject articles that explain how to implement delegates in C++.

But perhaps get familiar with the syntax of calling a function via a member function pointer first.
 
Share this answer
 
Comments
[no name] 25-Feb-13 4:20am    
Yes, I am thinking now...
I think in my class I may need a function pointer to a member function of ANY class...

and this: "-the member function pointer" as you mention, I think would require me to indicate in the class where I need function pointers the class name too -- which as I mentioned above might not be what I want ...
nv3 25-Feb-13 4:46am    
Perhaps you should explain what you are trying to accomplish.
[no name] 25-Feb-13 4:49am    
Well I have a class that may store as a callback a pointer to a function which can be a member of ANY class I suppose...
nv3 25-Feb-13 5:15am    
And here is the difference between a plain function pointer and a member function pointer. A member function pointer must always be applied to a particular object. You cannot simply call a member function without saying to which class object it is going to be applied.
[no name] 25-Feb-13 5:35am    
yes and that's why I think I can't avoid using wrapper functions... thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900