Reputation: 217
I'm trying to have pointer to class methods, so I have something like:
class foo {
public:
static void bar() {
}
};
void (foo::*bar)() = &foo::bar;
That doesn't compile :( I get:
> error: cannot convert ‘void (*)()’ to
> ‘void (foo::*)()’ in
> initialization
Upvotes: 2
Views: 1211
Reputation: 75615
A static method, when used by name rather than called, is a pointer.
void (*bar)() = foo::bar; // used as a name, it's a function pointer
...
bar(); // calls it
Upvotes: 4
Reputation: 96849
bar()
is a static function, in other words there is not this
parameter.
void (*myfunptr)() = &(foo::bar);
Upvotes: 2
Reputation: 791371
A pointer to a static member has the same type as a pointer to non-member.
Try:
void (*bar)() = &foo::bar;
Upvotes: 2