Greating everybody! I have a function-pointer method
int Myclass::*myMethod(char* a,char* b){
//some code
}
And try to run it
bool Myclass::myMethod2(){
AnotherClass *instance = AnotherClass:getInstance();
instance-> addParams(&myMethod);
return true;
}
AnotherClass - this class in another dll. AnotherClass definition
class AnotherClass
{
//friend class Myclass;
public:
static AnotherClass* getInstance();
void addParams(int (*myMethod)(char*, char*) =0);
//I try so void addParams(int (Myclass::*myMethod)(char*, char*) =0);
};
And have error C2664. Cannot convert parameter 1 from 'int Myclass::* (__cdecl *)(char *,char *)' to 'int (__cdecl *)(char *,char *).
Hm.. What should i do?
AnotherClasslooks badly-designed, since it takes just a function pointer, with no context belonging to the caller. Your caller apparently wants to provide some context (when calling a non-static member functionMyMethodon a particular instance ofMyclass, you need something forthisto point to). C-style callback interfaces usually have a user data pointer for this, in C++ you can do the same, or use polymorphism. Depending how important the dll boundary is, you could perhaps makeaddParamsa template. - Steve Jessop