2012-03-25 4 views

risposta

15

Basta mettere in come si farebbe con qualsiasi altro campo:

struct example { 
    int x; 
    DoRunTimeChecks y; 
}; 

void Function(void) 
{ 
} 

struct example anExample = { 12, Function }; 

Per assegnare al campo:

anExample.y = Function; 

per chiamare la funzione:

anExample.y(); 
4
#include <stdio.h> 

typedef void (*DoRunTimeChecks)(); 

struct func_struct { 
    DoRunTimeChecks func; 
}; 

void function() 
{ 
    puts("hello"); 
} 

int main() 
{ 
    struct func_struct func_struct; 
    func_struct.func = function; 
    func_struct.func(); 
    return 0; 
}