Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old August 28th, 2008, 02:11 PM
Member
 
Join Date: Mar 2007
Posts: 47
Default Function pointer with in classes

Ok im trying to use function pointer with in a class. So far i have this

cpp file
Expand|Select|Wrap|Line Numbers
  1.  
  2. void Camera::vUpdate( const float &fTimeMovement )
  3.     {        
  4.         vec2Rotation = C_Input.vec2Update( fTimeMovement, vStrafeCamera, vMoveCameraFoward );
  5.     }
  6.  
  7.     void Camera::vStrafeCamera( const float &fMovement )
  8.     {
  9.            // does stuff
  10.     }
  11.  
  12.     void Camera::vMoveCameraFoward( const float &fMovement )
  13.     {
  14.         // does stuff
  15.     }
  16.  
  17.  
the vec2Update is a function from a different class with in the program which looks like this

Expand|Select|Wrap|Line Numbers
  1. D3DXVECTOR2 vec2Update( const float &fTimeMovement, void (*Strafe)(const float&), void (*Advance)(const float&) )
  2. {
  3.               // stuff
  4. }
  5.  
Error 1 error C3867: 'Graphics::Camera::vStrafeCamera': function call missing argument list; use '&Graphics::Camera::vStrafeCamera' to create a pointer to member c:\Users\Lee\Desktop\Summer

The problem is that the compiler i think gets confused, thinking i need to pass a variable through the functions like so ->

vec2Update( fTimeMovement, vStrafeCamera(variable), vMoveCameraFoward(variable) )

of course, with out compiling, you can see that would be completely wrong.

so any ideas how to fix this problem? with out making the functions global?
Reply
  #2  
Old August 28th, 2008, 03:35 PM
Newbie
 
Join Date: Jul 2008
Posts: 12
Default

Unfortunately, you can't do what you are doing. A method and a function aren't the same thing. So you declaration of vec2Update is wrong if it is a member function you want to pass. Also, you have to be conscious that a method is always associated to an object, while a function is all alone in the universe.

So your definition/declaration of vec2Update should be written like this:

Expand|Select|Wrap|Line Numbers
  1. D3DXVECTOR2 vec2Update( const float &fTimeMovement, Camera* Cam, void (Camera::* Strafe)(const float&), void (Camera::*Advance)(const float&) )
  2. {
  3.   // Now you can call:
  4.   (Cam->*Strafe)(1.2);
  5.   (Cam->*Advance)(3.1);
  6. }
  7.  
Than your call would be:
Expand|Select|Wrap|Line Numbers
  1. vec2Rotation = C_Input.vec2Update( fTimeMovement, this, &Camera::vStrafeCamera, &Camera::vMoveCameraFoward );
  2.  
Hope this helps!
Reply
  #3  
Old September 10th, 2008, 04:40 PM
Member
 
Join Date: Mar 2007
Posts: 47
Default

thank you very much for your help
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 204,687 network members.
Post your question now . . .
It's fast and it's free

Popular Articles