本文着重介绍函数指针,此处的用法也许可用于实现c语言的面相对象编程。
#include <afx.h> void hello() { printf("hello"); } void good() { printf("good"); } void same() { printf("same"); } typedef void (* funcPtr)(); int main() { #if 1 void (* ptr[3])()={hello,good,same}; #else funcPtr ptr[3] = {hello,good,same}; #endif funcPtr pp; for(int i=0;i<3;i++) { pp = ptr[i]; (*pp)(); } system("pause"); return 0; }