Within a non-static class, can I directly pass function member rhs as below? It reports some errors. I also tried to change it as mystepper.do_step(this->rhs)
It still doesn't work. But if I put mystepper.do_step(rhs);
in the main function, and rhs as a function, it works fine. How can I fix this problem? Many thanks!
void Animal::rhs(const double x , double &dxdt , const double t) {
dxdt = 2*t;
};
void Animal::response() {
mystepper.do_step(rhs);
}
I made some minimalist code to illustrate my previous question.Your help is highly appreciated!!
#include <iostream>
using namespace std;
class ABC{
private:
int x =3;
int add2num(int a, int b){
return a+b+x;
}
int worker(int &fun(int a, int b), int a, int b){
return fun(a,b);
}
public:
int doSomething(int a, int b){
return worker(add2num, a, b);
}
};
int main() {
ABC test;
cout << test.doSomething(3,5) << endl;
return 0;
}