Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 10th, 2008, 5:17 PM   #11
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 836
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Pointer to member function

I would be interested to see the code, if you would care to post it.
titaniumdecoy is offline   Reply With Quote
Old Feb 10th, 2008, 5:26 PM   #12
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 730
Rep Power: 4 Dameon is on a distinguished road
Re: Pointer to member function

Shouldn't this be straightforward using mem_fun from <functional>?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Feb 10th, 2008, 5:31 PM   #13
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 288
Rep Power: 4 Klarre is on a distinguished road
Re: Pointer to member function

Quote:
Originally Posted by Lakrids View Post
Lol thanks! But a fellow programmer just pointed me out that in fact, it is possible. And he wrote me code which works. The idea is to make a static wrapper member function which will call the non-static one. It also involves passing a pointer to the object, which is then converted into a void*, and in the member function itself, reconverted into the class's type, which will then be passed to the function as the first argument, the implicit "this". This way the wanted action is performed on the object in question, and always gives accurate results.

Remember, this is C++. Nothing is impossible.
Hehe, creative solutions for teh win!
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Feb 10th, 2008, 9:34 PM   #14
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,192
Rep Power: 5 grumpy is on a distinguished road
Re: Pointer to member function

Quote:
Originally Posted by Lakrids View Post
Lol thanks! But a fellow programmer just pointed me out that in fact, it is possible. And he wrote me code which works. The idea is to make a static wrapper member function which will call the non-static one. It also involves passing a pointer to the object, which is then converted into a void*, and in the member function itself, reconverted into the class's type, which will then be passed to the function as the first argument, the implicit "this". This way the wanted action is performed on the object in question, and always gives accurate results.
And, if you had read my earlier posts carefully, you would see that I noted you need to do a similar thing (i.e. pass information about the object and about the function to act on it). The only difference, clearly, is that I was not willing to implement it for you.
grumpy is offline   Reply With Quote
Old Feb 11th, 2008, 9:38 AM   #15
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Pointer to member function

This is also possible with Boost.Bind + Boost.Function. Example:
cpp Syntax (Toggle Plain Text)
  1. class button
  2. {
  3. public:
  4.  
  5. boost::function<void> onClick;
  6. };
  7.  
  8. class player
  9. {
  10. public:
  11.  
  12. void play();
  13. void stop();
  14. };
  15.  
  16. button playButton, stopButton;
  17. player thePlayer;
  18.  
  19. void connect()
  20. {
  21. playButton.onClick = boost::bind(&player::play, &thePlayer);
  22. stopButton.onClick = boost::bind(&player::stop, &thePlayer);
  23.  
  24. // Calls player::play() on thePlayer object
  25. playButton.onClick();
  26. }
__________________
Robotics @ Maryland AUV Team - Software Lead
Game_Ender is offline   Reply With Quote
Old Feb 11th, 2008, 1:35 PM   #16
Lakrids
Newbie
 
Join Date: Dec 2007
Posts: 28
Rep Power: 0 Lakrids is on a distinguished road
Re: Pointer to member function

Quote:
And, if you had read my earlier posts carefully, you would see that I noted you need to do a similar thing (i.e. pass information about the object and about the function to act on it). The only difference, clearly, is that I was not willing to implement it for you.
Yes, that's right. But I couldn't resist accepting an already-done code... As for the boost code, thank you, that could also help me.

As for finally getting to the very bottom of (non-)static member function pointers, here's an excellent site with lots of examples :

http://www.newty.de/fpt/callback.html

Thanks to all for the help!
Lakrids is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Incompatible pointer type (double pointer in a function) Gabriel Margarido C 16 Nov 23rd, 2007 3:04 AM
Get member function address Klarre C++ 3 Mar 28th, 2007 6:34 AM
Function pointer to a member function Jimbo C++ 3 May 12th, 2006 4:53 PM
Need help writing a member function Rawr101 C++ 3 Apr 11th, 2006 3:18 AM
function pointer raom C 9 Nov 18th, 2005 2:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC