Original Post
i want to add functions to an array to call them later. i know its not possible over different classes, except with static declarations i tested a little and got stuck ... it should be used for example as callbacks for actions in an inputsystem( for mouse and keyboard) compiler says he cant cast int testfunc"( int, char*)" into "somefunc (__cdecl *)" ... any suggestions ?
typedef int (somefunc)( int a, char *b);
class A {
public:
somefunc *funcs[10];
int counter;
A() {
memset( funcs, 0, sizeof( somefunc* ) * 10 );
counter= 0;
}
void addAction( somefunc *func) {
funcs[counter]= func;
++counter;
}
void go() {
for( int i= 0; i < counter; ++i ) {
if( NULL != funcs ) {
funcs( i, 0 );
}
}
}
};
class B : public A {
public:
int testfunc( int a, char *b ) {
printf( "huhu %i\n", a );
return 0;
}
B() : A() {
addAction( testfunc );
}
};
int main( int argc, char **args ) {
B test;
B.go();
return 0;
}