jeudi 6 août 2020

map to a function pointer with different number of arguments and varying datatypes

There is multiple class with different functions. For example:

  class A
  {
    public:
      int sum(int a, int b);
      bool isScalable(double d);
  }

  class B
  {
    public:
      std:string ownerName();
  }

My aim is to create a map of all the function names as below

        std::map<std::string, FnPtr> myMap;

        // Add the newly implemented function to this map
        myMap["sum"] = &A::sum;
        myMap["isScalable"] = &A::isScalable;
        myMap["myMap"] = &B::myMap;

The issue is I am not aware how I can define FnPtr. Can you please help me out.

Aucun commentaire:

Enregistrer un commentaire