Pass a pointer to a static method
c++, function-pointers, pointer-to-member, pointers
Solution
You declared the function foo as static.
It is therefore not a member function of a Foo instance.
This code works:
class Foo
{
public:
static void foo ( void ){}
void foo2() {}
};
void foo ( void(*)(void) ){}
void fooMember ( void(Foo::*)(void) ){}
int main()
{
foo(&Foo::foo);
fooMember(&Foo::foo2);
return 0;
}
EDIT: I updated the description and added a piece of code.
Problem
Why does the compiler treat `&Foo::foo` as `void (*)()`. I am expecting it to be treated as `void(Foo::*)()` instead since it's a member of `Foo`. ``` class Foo { public: static void foo ( void ){} }; void foo ( void(Foo::*)(void) ){} int main() { foo(&Foo::foo); // error: cannot convert ‘void (*)()’ to ‘void (Foo::*)()’ return 0; } ```