'How to define a function pointers and and structure?
How to define a function pointers with a structure as parameter... and that structure contains the function pointer ?
This code doesn't compile :
typedef struct _INFOS_STRUCT {
int val1;
PTR_NEXT_ACTION nextAction;
//void* (*nextAction)(struct _INFOS_STRUCT * infos); // how to replace void* by PTR_ACTION* ?
} INFOS_STRUCT;
typedef void (*PTR_ACTION)(INFOS_STRUCT * infos);
typedef PTR_ACTION (*PTR_NEXT_ACTION)(INFOS_STRUCT * infos);
INFOS_STRUCT infos_list[10];
void run(int index){
INFOS_STRUCT * infos = &infos_list[index];
PTR_ACTION action = infos->nextAction(infos);
while(action){
action(infos);
action = infos->nextAction(infos);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
