#include "stdafx.h"
typedef int(__stdcall *ptr)(char *p); // 声明Callback 类型的函数指针
int A(char *p){
std::cout<<p<<std::endl;
return 0;
}
int C(char *p){
std::cout<<"***"<<p<<"***/n";
return 0;
}
int B(int(*pp)(char *),char *p)
{
pp(p);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
char *p = "hello, everyone!";
B(A,p);
B(C,p);
return 0;
}
本文通过一个简单的C++程序介绍了如何定义和使用函数指针。程序中定义了两个函数A和C,并通过函数B调用传入的函数指针实现间接调用。这个例子展示了函数作为参数传递的基本用法。
7859

被折叠的 条评论
为什么被折叠?



