This Code create a vector of functions.
1
2
3
4
5
6 typedef struct _clase{
7 int a;
8 void(*func[3])(struct _clase*);
9 } clase;
10
11 void clase_func1 (struct _clase *p){
12 printf("Funcion 1: %i\n",p->a);
13 }
14
15 void clase_func2 (struct _clase *p){
16 printf("Funcion 2: %i\n",p->a);
17 }
18
19 void clase_func3 (struct _clase *p){
20 printf("Funcion 3: %i\n",p->a);
21 }
22
23 void holaMundo(){
24 printf("Hola Mundo!\n");
25 }
26
27 typedef void(*func) (void);
28
29
30 int main(int argc, char *argv[])
31 {
32 func val;
33 clase c;
34
35 c.func[1]=&clase_func1;
36 c.func[2]=&clase_func2;
37 c.func[0]=&clase_func3;
38
39 val=&holaMundo;
40 val();
41 c.a=1;
42 c.func[0](&c);
43 c.a=2;
44 c.func[1](&c);
45 c.a=3;
46 c.func[2](&c);
47 system("PAUSE");
48 return 0;
49 }
50