title: Using one function pointer to two different member function from different classes
body: <p>I am training to encapsulate some codes and for this I created three classes, which are Vero, Pionner and Vehicle. The first two classes have the member variable cmd and the member function getcmd - in each classes theses members are slightly different. Then. we have the class Vehicle, which is a subclass of Vero and Pionner. The Vehicle constructor has the parameter <strong>which_car</strong> that should be used to select which of the two classes we want to work with. </p>
  
  <p>I would like to have some kind of <strong>function pointer</strong> that could point to the getcmd member function of the class Vero or of the class Pionner. How could a perform this task? </p>
  
  <p><strong>COMMENT</strong>: I am not asking about how to just create a member point. I am asking how can I, somehow, create a generic type that can point or to Vero objects or to Pionner objects.</p>
  
  <p>The code I am working on.</p>
  
  <p><strong>HEADER</strong></p>
  
  <pre><code>#ifndef VEHICLE_H
  #define VEHICLE_H
  
  #include &lt;ros/ros.h&gt;
  #include &lt;geometry_msgs/Twist.h&gt;
  #include &lt;ransac_project/CarCommand.h&gt;
  
  
  class Vero{
  public:
      ransac_project::CarCommand cmd;
  
      Vero();
      void getcmd(const double &amp;velocity, const double &amp;steering);
  };
  
  
  class Pionner{
  public:
      geometry_msgs::Twist cmd;
  
      Pionner();
      void getcmd(const double &amp;linear_vel, const double &amp;angular_vel);
  };
  
  
  class Vehicle: public Vero, public Pionner{
  public:
      Vehicle(const std::string &amp;which_car);
      void (*arrangemessage) (const double &amp;, const double &amp;);
  };
  
  #endif /* VEHICLE_H */
  </code></pre>
  
  <p><strong>SOURCE</strong></p>
  
  <pre><code>#include "vehicle.hpp"
  
  Vero::Vero(){
      cmd.speedLeft  = 0.0; cmd.speedRight = 0.0; cmd.steerAngle = 0.0;
      return;
  }
  
  void Vero::getcmd(const double &amp;velocity, const double &amp;steering){
      cmd.speedLeft  = velocity;
      cmd.speedRight = velocity;
      cmd.steerAngle = steering;
      return;
  }
  
  Pionner::Pionner(){
      cmd.linear.x  = 0.0; cmd.linear.y  = 0.0; cmd.linear.z  = 0.0;
      cmd.angular.x = 0.0; cmd.angular.y = 0.0; cmd.angular.z = 0.0;
      return;
  }
  
  void Pionner::getcmd(const double &amp;linear_vel, const double &amp;angular_vel){
      cmd.linear.x = linear_vel;
      cmd.linear.y = 0;
      cmd.linear.z = 0;
      cmd.angular.x = 0;
      cmd.angular.y = 0;
      cmd.angular.z = angular_vel;
      return;
  }
  
  
  Vehicle::Vehicle(const std::string &amp;which_car){
      if(which_car.compare("vero")==0){
          arrangemessage = &amp;Vero::getcmd;
      }
      else if(which_car.compare("pionner")==0){
          arrangemessage = &amp;pionner.getcmd;
      }
      else{
          ROS_INFO_STREAM("which_car must be vero or pionner");
          exit(0);
      }
  }
  </code></pre>