473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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?
Aug 28 '08 #1
2 1215
Sirmont
12
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!
Aug 28 '08 #2
thank you very much for your help
Sep 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
12
by: Joe | last post by:
Hi, Can I pass a "generic" class pointer as an argument to a function? For instance say classA and B are both derived from Z. { int iType =1;
11
by: Enquiries, Hopkins Research | last post by:
Hi all I have a conundrum that is puzzling me. I have a large codebase in C that I am converting to C++ as fast as possible (i.e. slowly because I keep learning new idioms and stumbling with...
10
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
5
by: mancomb | last post by:
Hi, I'm curious to the syntax of calling member functions through pointers of classes returned through the -operator. For example (excuse the crude incomplete code); Here are the classes: ...
43
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions...
7
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.