Here is what I'd like to do. I have a function pointer which wants a function like this:
void func(int a);
so I have a class:
class Foo {
public:
void func(int a)开发者_高级运维;
};
Foo *foo = new Foo;
something->setFunction(foo->func);
or in my case:
testWidget[count] = new TestWidget;
testWidget[count]->eventMouseClick.addHandler(testWidget[0]->silly);
But this gives me:
Error 5 error C3867: 'TestWidget::silly': function call missing argument list; use '&TestWidget::silly' to create a pointer to member c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\main.cpp 190
Is there a way I could make this work without using a static function?
Thanks
Is there a way I could make this work without using a static function?
No. You can't convert a pointer to member function to an ordinary function pointer.
If the callback accepted any callable object (or a std::function
, for example), then you could bind the object to the member function and pass the result of that; unfortunately, you can't convert that result to an ordinary function pointer, though.
Your question is not very clear to me. But the error message from the compiler makes me feel that probably you want something like this something->setFunction(&foo->func);
An example might help in case of overloads
struct T{
void func(int){}
void func(double){}
};
void f(void (T::*f)(int)){}
void f(void (T::*f)(double)){}
int main(){
void (T::*fi)(int) = &T::func;
void (T::*fd)(double) = &T::func;
f(fi);
f(fd);
}
精彩评论