Sign in to follow this  
Farraj

Function pointer as a class method?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this