I have a class with a list of function pointers. These function pointers point to a member function of a sub-class, which was bound like this:
functionList.push_back(std::bind(&SubClass::function, this, std::placeholders::_1, std::placeholders::_2));
Now, when copying the class with functionList, the function pointers still point to the old class. How can I rebind the function pointer to the new class?
Here an example code:
#include <vector>
#include <functional>
class SomeClass
{
};
class testClass
{
public:
typedef std::function<void(const SomeClass& var1, const SomeClass& var2)> transitionFunction;
testClass(){}
testClass(const testClass&s)
{
for(transitionFunction func : s.functionList)
{
// how to rebind the function pointer to the new this?
functionList.push_back("???");
}
}
std::vector<transitionFunction> functionList;
};
class SubClass : public testClass
{
SubClass()
{
functionList.push_back(std::bind(&SubClass::function, this, std::placeholders::_1, std::placeholders::_2));
}
void function(const SomeClass& var1, const SomeClass& var2)
{
}
};
Thanks!