Reputation: 6240
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;
}
Upvotes: 5
Views: 3991
Reputation: 1244
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.
Upvotes: 4