반응형
#include <stdio.h>
#include <stdlib.h>
typedef struct tagParent{
char(*func)();
}Parent;
static char a_func()
{
return 'A';
}
static char b_func()
{
return 'B';
}
static Parent* create(char(*func)())
{
Parent* ret = (Parent*)malloc(sizeof(*ret));
ret->func = func;
return ret;
}
int main()
{
Parent* ob1 = create(a_func);
Parent* ob2 = create(b_func);
printf("%c %c\n", ob1->func(), ob2->func());
free(ob1);
free(ob2);
return 0;
}
함수포인터는 따로 공부하셔야 합니다.
좋은 글들이 많이있네요~
http://shinluckyarchive.tistory.com/206
http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/C/Documents/FunctionPointer
반응형