There are several things wrong with the example, but I will stick with the question asked.
The declaration "
double (*person::getSalary)();
" should not have compiled.
The declaration of a pointer to a member function would be
double (person::*getSalary)();
.
Since your code example implies you want to point to a global function the correct declaration would be
double (*getSalary)();
.
The following should give you the general idea.
#include <cstring>
double getSalary(int v, double s) { return v * s; }
double getSalary(double s) { return s/2; }
double getSalary() { return 1000; }
class person
{
public:
char name[20];
int age;
double salary;
person(char* num="Anonim",int a=0, double s=0) : age(a), salary(s)
{
strcpy(name,num);
getSalary = ::getSalary;
getIt = ::getSalary;
}
double (*getSalary)();
double (*getIt)();
};
void test()
{
person p("John",25,3000);
std::cout << "Salary is " << p.getSalary() << std::endl;
std::cout << "Salary is " << p.getIt() << std::endl;
}