I have read a number of posts about passing a pointer to a class method to a different classes method, but couldn't find a clear answer/understand how I should approach my specific problem.
Some that I looked at:
Passing a pointer to a class member function as a parameter
C++ Pass a member function to another class
I would really appreciate help making my particular scenario work.
I have three classes: Eom, Rk4, and Manage. In the first class I have two methods, get_pos and set_pos.
class Eom
{
public:
// Get methods
double get_pos() {return pos;}
// Set methods
void set_pos(double pos_in) {pos = pos_in;}
private:
double pos;
};
In the second class I have a method called integrate that I want to pass Eom::get_pos and Eom::set_pos method to.
class Rk4
{
public:
// Method that takes a method to get_pos
// and a method to set_pos as input
void integrate(Eom *p_get_func, Eom *p_set_func);
};
The Manage class run method is where I want to create the pointer objects to Rk4 and Eom, and call the Rk4 integrate method.
class Manage
{
public:
// Declare pointers
Eom *p_eom;
Rk4 *p_rk4;
// Run method
void run();
};
Manage::run()
{
p_eom = new Eom;
p_rk4 = new Rk4;
// Call integrate, passing in the Eom get_pos and set_pos functions;
p_rk4->integrate(p_eom->get_pos, p_rk4->set_pos);
}
I currently get the following errors:
invalid use of non-static member function
p_rk4->integrate(p_eom->get_pos, p_eom->set_pos);
I would also like to declare the integrate method in a more generic fashion so that I could pass in get/set methods from other classes:
void integrate(Generic_class *p_get_func, Generic_class *p_set_func);
Thanks for any help in advance!