Archived

This topic is now archived and is closed to further replies.

functions inside classes.

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites