int Person::WorkingWithPointers8(int i, int j, int(*pfunc)(int,int))
{
//note the parameter defined for the pointer to a function.
int a = pfunc(1,10);
return a;
}
int Person::WorkingWithPointers9(int i, int j)
{
return (i+j);
}
void Person::WorkingWithPointers10()
{
int i = WorkingWithPointers8(10,11,WorkingWithPointers9); //This doesn't work for some reason
}
There is no WorkingWithPointers9 function in your code. THere is a Person::WorkingWithPointers9 one. Correct signature would be: int WorkingWithPointers8(int, int, int(Person::*)(int,int));
And you cannot call nonstatic member function like pfunc(1,10);. You need an object to call it on.
Read this FAQ: https://isocpp.org/wiki/faq/pointers-to-members
int Person::WorkingWithPointers8(int i, int j, int(Person::*pfunc)(int,int))
{
int a;
a = pfunc(10,11); //HELP! - Unsure what exactly goes in here. Should I create the Person object?
return a;
}
int Person::WorkingWithPointers9(int i, int j)
{
return (i+j);
}
void Person::WorkingWithPointers10()
{
int i = WorkingWithPointers8(10, 11, &Person::WorkingWithPointers9);
}
Well, you cannot call nonstatic member function without object, so yes.
However, have you considered making WorkingWithPointers9 non-member function? Or static member function (which does not need object)?