Original Post
Hi, I'm trying to store a list of function pointers and at the moment it looks something a bit like this : When I try to add a non-member function to the list it has no problems i.e. But when I try to add a member function of a class to the list, it doesn't like it I get the following error : error C2664: 'MyClass::registerFunction' : cannot convert parameter 1 from 'float (float,float)' to 'MyClass::myFunc' How can I get to accept this function as an argument to registerFunction? Thanks in advance!
class MyClass
{
private:
typedef float(*myFunc)(float a, float b);
vector<myFunc> myFunctionPointers;
public:
void fun()
{
for(unsigned char i=0;i<myFunctionPointers.size();i++)
{
myFunctionPointers(1.0f, 2.0f);
}
}
void registerFunction(myFunc function)
{
myFunctionPointers.push_back(function);
}
};
float testFunction(float a, float b)
{
return a*b;
}
int main()
{
MyClass myInstance;
myInstance.registerFunction(testFunction);
return 0;
}
class MyOtherClass
{
private:
MyClass myInstance;
public:
float memberFunc(float a, float b)
{
return a*b;
}
MyOtherClass()
{
myInstance.registerFunction(memberFunc);
}
};