| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 530 人关注过本帖
标题:回调函数的问题 高手请进啊
只看楼主 加入收藏
天各一方2010
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2010-5-27
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:1 
回调函数的问题 高手请进啊
我要写一个回调函数 walkList(int(callback)(pid_t,const char *)
然后我这么写的:
typedef int (*callback)(pid_t,const char *);
void walkList(callback);
int printlist(pid_t,const char *){
    temp=head;
    if(head==NULL) return (-1);
    else{
        while(temp->next!=NULL){
            printf("%d,%s",temp->pid_element,temp->commandLine);
        temp=temp->next;
        }
    }
        printf("%d,%s\n",temp->pid_element,temp->commandLine);
        return(0);
}

void walkList(callback f){
    f(pid_t,const char *);
}
在主函数中这样调用:
walkList(printlist);
结果在编译的时候:
说这行int printlist(pid_t,const char *){
parameter name omitted
然后说这行  expected expression before pid_t
too few arguments to function f;
请问这是为什么呢  哪位高手能帮我改改?谢谢啦
搜索更多相关主题的帖子: 回调 函数 
2010-05-30 10:10
kingsroot
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:284
专家分:1159
注 册:2010-3-28
收藏
得分:20 
你回调函数没有参数 你传入printlist的时候 他的参数也要传进入 walkList(printlist,pid_t,const char *);然后调用的时候void walkList(callback f){
    f(pid_t,const char *);
}才对头
2010-05-30 10:54
快速回复:回调函数的问题 高手请进啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014154 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved