用函数的参数怎么调用另外一个函数?

to_be_or_not_to_be 2004-10-11 11:20:22
例如:
void aa();
void bb(void (__cdecl *) (void * aa));
我看了process.h文件,里面的_beginthread()函数就是用void (__cdecl *) (void *)来载入另外一个函数的,请问在bb()函数里面,怎么触发aa()函数呢?
...全文
169 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
daylove 2004-10-11
  • 打赏
  • 举报
回复
是不是这样:
和一般的参数调用一样,当函数是参数时,先执行此函数,结果作为调用函数的参数!
elvahuang 2004-10-11
  • 打赏
  • 举报
回复
对的 是函数指针了

void func(){}

void callfunc( void (*a) () ){ a(); }
sharkhuang 2004-10-11
  • 打赏
  • 举报
回复
函数指针。但是返回值参数要一样!不然会有warning
hcj2002 2004-10-11
  • 打赏
  • 举报
回复
用函数指针



insulator 2004-10-11
  • 打赏
  • 举报
回复
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//function that prints the passed argument
void print (int elem)
{
cout << elem << ' ' ;
}
int main()
{
vector<int> coll;
//insert elements from 1 to 9
for (int i=1; i<=9; ++i) {
coll.push_back(i);
}
//print all elements
for_each (coll.begin(), coll.end(), print); //cout << endl;
}
insulator 2004-10-11
  • 打赏
  • 举报
回复
c++的stl函数里面有很多的是将函数作为参数。
fallhunter 2004-10-11
  • 打赏
  • 举报
回复

真的是这样的么?

定义一个函数指针:
返回类型 (*变量名)(函数参数表)
如;
int (*pf)(void);
凡是类型和参数一样的都能赋值
如:
int fun(void);

pf = fun;

调用是就是
pf();
oo 2004-10-11
  • 打赏
  • 举报
回复
void bb(void (__cdecl *) (void * aa)); //这里的aa跟那个aa函数没关系的吧。
这个是定义的地方吧,在实现的地方应该有个参数名的,比如:
void bb(void (__cdecl *func) (void * a));
然后在bb里调用的时候:(*func)(cc); cc为void*类型

调用bb: bb(aa);//不过你的aa定义跟bb的参数定义不匹配,应该void aa(void*);才匹配。
visual4825 2004-10-11
  • 打赏
  • 举报
回复
<<c++ programming language>>中关于namespace一节,参考
applebomb 2004-10-11
  • 打赏
  • 举报
回复
http://dev.csdn.net/article/9/article/16/article/18/18162.shtm
breay 2004-10-11
  • 打赏
  • 举报
回复
路过!!
有待研讨!!
ccj200308053 2004-10-11
  • 打赏
  • 举报
回复
hehe

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧