I\'m trying to figure out a way of how to be able to assign a function pointer to functions with different number of arguments.
I have a while loop which takes a nu
You could use std::function<> and std::bind().
#include
using std::placeholders::_1;
typedef std::function my_fun_t;
my_fun_t my_fun;
if (condition1)
my_fun = std::bind(&MyClass::function_one, _1);
else if (condition2)
my_fun = std::bind(&MyClass::function_two, _1, a, b);
else if (condition3)
my_fun = std::bind(&MyClass::function_three, _1, a, b, c);
else if (condition4)
my_fun = std::bind(&MyClass::function_four, _1, a, b, c, d);
while (my_fun(my_class)) { ... }
These assumes you will use C++11. If you can't use C++11 but can use TR1, replace all std:: with std::tr1::. There is also a Boost implementation.