Storing the function pointers in vector of function pointers

I am writing a code to store function pointers in a vector of function pointers. But in my implementation, the function that I am going to store in a vector is a member function of a class that is stored in another std::map as a pointer. Below is the code snippet.

class img_preprocess(){ 
public:
   std::vector<void(*)(int)> receivers;
}

class detector(){
public:
   void push(int val) {
      //some code here
   }


class tracker(){
private:
   std::map< int, img_preprocess* > img_actors;
   std::map< int, detector* > detect_actors;

public:
   tracker(){
      this->img_actors.insert({ 1, new img_preprocess() });
      this->detect_actors.insert({ 1, new detector() });

      // adding the detector::push function to img_preprocess receivers vector
      this->img_actors[1]->receivers.push_back(
          & ( this->detect_actors[1]->push )       // this line gives me the error
      )
   }
}

My intention is to keep a function pointer for the push function of the detector object inside of the img_preprocess object’s receivers vector. The above approach gives me the a pointer to a bound function may only be used to call the function error. Any ideas on how to overcome this error and accomplish my intention?

Source: Windows Questions C++

LEAVE A COMMENT