Created
January 21, 2012 00:58
-
-
Save mastbaum/1650524 to your computer and use it in GitHub Desktop.
A sad, non-working example of a pointer to a non-static member function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
/* A sad, non-working example of a pointer to a non-static member function */ | |
class Foo { | |
public: | |
int threadMe(int a) { | |
std::cout << "Foo::threadMe: a = " << a << std::endl; | |
} | |
}; | |
int main(int argc, char* argv[]) { | |
// create an instance | |
Foo* o = new Foo; | |
// create pointer to static member | |
int (*pStaticMemberFunction)(int); | |
// assign it | |
pStaticMemberFunction = &(o->threadMe); | |
// call it | |
(*pStaticMemberFunction)(42); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment