C++辅导:C++函数(函数指针实例)

C++辅导:C++函数(函数指针实例),第1张

C++辅导:C++函数(函数指针实例),第2张

# include
typedef void(* myTest)(int I);
void test1(int I)
{
printf(" hello test1,my value:%d\n ",I);
}
void test 2(int I)
{
printf(" hello test 2,my value:%d\n ",I);
}
int main()
{
myTest my fun;//定义一个myTest
myFun=test1类型的变量;//将函数赋给变量myFun,exam。大注意myFun是一个指向函数指针的变量
(* my fun)(1);//execute
my fun = test 2;//赋另一个值
(* my fun)(2);//再次执行。
返回0;
}
Liu life @ Liu life:~/test $ gcc-o test _ func _ p test _ func _ p . c
Liu life @ Liu life:~/test $ ls
test _ func _ p test _ func _ p . c
Liu life @ Liu life:~/test $。/test_func_p
hello test1,我的值:1
hello test2,我的值:2

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » C++辅导:C++函数(函数指针实例)

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情