Jump to content
  • Advertisement
Sign in to follow this  
Farraj

Function pointer as a class method?

This topic is 3769 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

OK, I got a question. Is there a way to 'access' a class's methods or members (public or private) inside a global function so if I to use that as a function pointer in that class it would work?? Example: //////////////////// // The class class Foo { public: void Boo(); void (*Do)(*void); // this is the target to be tested }; // function to be pointer void Do(void) { this->Boo(); } // put them all together Foo foo = new Foo(); foo->Do = Do; foo->Do(); //////////////////// I know this doesn't work. The global function is not allowed to access the Foo's methods. Is there anyway I can go around this?? Using the class as an argument in the global function would work, but I would really rather not do that. Especially that I want to access the private members too. Hope it's clear. And thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Farraj
Is there anyway I can go around this?? Using the class as an argument in the global function would work, but I would really rather not do that. Especially that I want to access the private members too.

this is meaningless outside of a class definition, so no. You're going to need to find some other solution.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!