I have read many posts and answers about pointers to non-static member functions, but none looks able to solve my problem.
So I have created a short example to replicate my issue here: even if this example could be "solved" in different ways, for the final software it is important to keep the structure like in the example, thanks.
This is the header of the class "Funcs.h":
class Funcs
{
private:
double a = 1, b = 2;
public:
Funcs();
~Funcs();
double Fun1(double X);
double solver(double X0);
double aaa(double(*fun)(double), double x0);
};
This is the cpp of the class "Funcs.cpp":
#include "Funcs.h"
using namespace std;
Funcs::Funcs()
{
}
Funcs::~Funcs()
{
}
double Funcs::Fun1(double X) {
double f1 = a*X;
return f1;
}
double Funcs::solver(double X0)
{
double result;
result = aaa(Fun1, X0);
return result;
}
double Funcs::aaa(double(*fun)(double), double x0)
{
return fun(x0);
}
And Finally this is the main "main.cpp":
#include <iostream>
#include "Funcs.h"
using namespace std;
int main() {
double x0=1;
double result;
Funcs funcs;
result = funcs.solver(x0);
cout << result << endl;
return 0;
}
The error is in the method Funcs::solver when I call "result = aaa(Fun1, X0);" because I can't use a pointer to Fun1 because it is a non-static member. At the same time I can't make it static, otherwise the variable "a" could not be seen inside the static method.
Thanks in advance for your help.