I get an error on the following code. It seems I can´t use a function which belongs to a class as an argument for "genericfunction".
Any help on how to overcome the problem would be great.
Thanks.
//Main
int main()
{
teste teste_classe;
// this works fine
cout << teste_classe.genericfunc(1.0,2.0,sum_2)<< endl;
// this returns an error saying function is not of type double(*)(double,double) !!!
cout << teste_classe.genericfunc(1.0,2.0, teste_classe.sum )<< endl;
system("pause");
return 0;
};
//Header
double sum_2(double a, double b);
class teste
{
public:
double sum(double x, double y);
double genericfunc(double x, double y, double (*f)(double x, double y) );
};
//Cpp
#include "teste.hpp"
double sum_2(double a, double b)
{
return a+b;
};
double teste::sum(double x, double y)
{
return x+y;
};
double teste::genericfunc(double x, double y, double (*f)(double x, double y))
{
return f(x,y);
};