Im bit new to c++, please let me describe my problem. I have a class called CSubcriber, which main purpose is to execute some callback function, of some type and some number of arguments. For example callbacks can be:
typedef void (*cb1)(void)
typedef int (*cb2)(int, int)
typedef char (*cb3)(int, int, void);
class itself is:
template <class CallbackType>
class CSubscriber {
public:
CSubscriber();
virtual ~CSubscriber();
CallbackType (*m_callback_newWay)(void *params);
void (*m_callback)(void *params);
int (*m_callback_int)(void *params);
void *m_cb_params;
int execute_cb();
void *m_params;
CSubscriber(void (*callback)(void *params), void *cb_params);
CSubscriber(int (*callback)(void *params), void *cb_params);
};
CSubscriber::CSubscriber(void (*callback)(void *params), void *cb_params){
m_callback = callback;
m_cb_params = cb_params;
}
CSubscriber::CSubscriber(int (*callback)(void *params), void *cb_params){
m_callback_int = callback;
m_cb_params = cb_params;
}
My main problem is now, how to write constructor, which will handle with all that variable arguments to callback. After constructing object in some particular moment, callback may be fired, for example:
typedef int (*callback)(void *params);
CSubscriber s(callback, params);
or
typedef void (*callback2)(void *params, int arr, char *ptr);
CSubscriber s(callback, params, arr, ptr);
Now, calling
s->m_callback()
I want to execute callback with all arguments which i passed for constructor. I'd like to avoid writing ten different constructors, for each different number of arguments passed to callback function. Is it possible to do ?