functions inside classes.

Started by
3 comments, last by paulbird 21 years ago
In C++ I can make a pointer to a function like so: int myFunction(float x){.....}; int (far* F)(float x); F=myFunction; but if the function is in a class it doesn't seem to work class myClass{ public: int myFunction(float x){....}; } A; int (far*F)(float x); F=A.myFunction; Is there a solution to this conundrum? [edited by - paulbird on March 25, 2003 10:06:22 AM]
Advertisement
try making the function in the class/ or in other function(cant remember) static. If it doesnt work, make both static.

.lick
http://www.function-pointer.org/
The function-pointer link is what you want.

Basically though the functions of a class need to be called on an object. The only exception is when the function is static. A static function in a class can only make use of static variables and other static functions as there are no instance variables available. All none static member functions have a hidden variable passed to them accessible as the ''this'' pointer. It is a pointer to the object. So you need to make sure that is available when you''re using pointer to member functions. Hope that helps. It''s all made clear on the previous link.
http://www.parashift.com/c++-faq-lite/pointers-to-members.html
This should also help.

This topic is closed to new replies.

Advertisement