I don't have much experience using array of functions in C++. I need to use an array of functions where the array contains functions from different objects. Here is some dummy code to illustrate what I want to implement.
class base_class
{
public:
virtual int function1(int arg1, int arg2);
virtual int function2(int arg1, int arg2);
};
class derived_class : public base_class
{
public:
int function1(int arg1, int arg2) { /* ... */ };
int function2(int arg1, int arg2) { /* ... */ };
// ...
};
typedef int (*functions) (int arg1, int arg2);
int main()
{
derived_class object1;
derived_class object2;
functions func_instance[4];
func_instance[0] = object1.function1;
func_instance[1] = object1.function2;
func_instance[2] = object2.function1;
func_instance[3] = object2.function2;
// ...
}
I can't get it to work, it throws following error:
error: argument of type int () (int , int) does not match int (*) (int, int)
std::functionandstd::bind.