I want to have a class that would be able to keep as its fields a pointer to a function and a pointer to a structure holding is arguments. The interface of that object would be a method call() taking no arguments but passing saved arguments to the above mentioned function. A family of such classes for different arguments types and counts would have a common abstract ancestor with call being virtual.
As for now I have the following code which works, though adding the -pedantic option to g++ yields errors:
class Function {
protected:
void *data;
void *function;
public:
virtual void call() = 0;
};
class SingleArgumentFunction : public Function {
public:
SingleArgumentFunction( void (*f)(int), int i ) {
int *icpy = new int(i);
function = (void*) f;
data = (void*) icpy;
}
~SingleArgumentFunction() { delete (int*)data; }
inline void call() {
( *((void (*)(int))function) )( *(int*)data );
}
};
The error I get is as the title says:
warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object
How to handle that?