I am trying to do something with pointers to functions that I cannot understand how this works.
I have a class A that looks something like this:
class A
{
public:
float Plus (float a, float b) { return a+b; }
float Minus (float a, float b) { return a-b; }
float Multiply(float a, float b) { return a*b; }
float Divide (float a, float b) { return a/b; }
};
I want to declare a pointer to A, and then pass another function pointer to a function pointer to one of A.
Something like:
void Will_Get_Function_Pointer(float a, float b, float (A::*pt2Func)(float, float))
{
(...)
}
Where I would call it something like this
A* myA = new A;
Will_Get_Function_Pointer(1.00,2.00, &myA->Minus)
I cannot use static / const elements because in my last implementation A will point to a specific A in the collection of objects A in something that will look like
vector<A> vecA;
myA = &vecA[xxx]
Doing this fails
typedef float (A::*pA)(float x, float y);
pA p = &myA->Minus;
and the compiler tells me to use & A :: Minus, but this will not work for me.
Can I do it?
Greetings
source
share