C
christophe.verne
Hi all,
It's the first time I'm using groups so i hope I am posting on the good
group.
I''m not familiar with callback and function pointer and here is what
I'd like to do:
typedef struct Control{
TYPE Type;
unsigned int x;
unsigned int y;
unsigned int width;
unsigned int height;
void *callback;
};
with callback a pointer to a function. Control will be used in 2 cases,
and depending on the case, it will call one function or the other. As
the arguments are not the same, how can I declare it? I was thinking of
doing the following:
typedef (* case1) (int arg1, int arg2, float arg3);
typedef (* case2 )(int arg1, float arg2, char arg3);
Control panel;
Control menu;
new_(panel, PANEL_TYPE)
new_(menu,MENU_TYPE)
where new_ initialize panel and menu, making the callback pointing to
the good function...
In one case, I would call (case1) (panel.callback)(int1,int2,float3);
in the other case, I would call (case2)(menu.callback)(int1, float2,
char3)
Is this could work, or I have not understood how it works . I've
been looking for a tutorial on callbacks, but I haven't found something
for my problem, where a callback could be assigned to 2 differents
functions with differents arguments.
Thanks for the help.
ctitof
It's the first time I'm using groups so i hope I am posting on the good
group.
I''m not familiar with callback and function pointer and here is what
I'd like to do:
typedef struct Control{
TYPE Type;
unsigned int x;
unsigned int y;
unsigned int width;
unsigned int height;
void *callback;
};
with callback a pointer to a function. Control will be used in 2 cases,
and depending on the case, it will call one function or the other. As
the arguments are not the same, how can I declare it? I was thinking of
doing the following:
typedef (* case1) (int arg1, int arg2, float arg3);
typedef (* case2 )(int arg1, float arg2, char arg3);
Control panel;
Control menu;
new_(panel, PANEL_TYPE)
new_(menu,MENU_TYPE)
where new_ initialize panel and menu, making the callback pointing to
the good function...
In one case, I would call (case1) (panel.callback)(int1,int2,float3);
in the other case, I would call (case2)(menu.callback)(int1, float2,
char3)
Is this could work, or I have not understood how it works . I've
been looking for a tutorial on callbacks, but I haven't found something
for my problem, where a callback could be assigned to 2 differents
functions with differents arguments.
Thanks for the help.
ctitof