标题:函数指针问题。
取消只看楼主
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
 问题点数:0 回复次数:1 
函数指针问题。
这个程序大体意思我懂,但就是不大明白函数指针是怎样工作的?不清楚它的传值过程?望高手解释一下它的具体流程!谢谢!
#include<iostream>
using namespace std;
int f1(int a,int b){return a+b;}
int f2(int a,int b){return a-b;}
int f3(int(*t)(int,int),int a,int b){return (*t)(a,b);}
int main(){
int(*p)(int,int);//这句的作用?
p=f1;//这句跟下面一句的具体联系是怎样的?
cout<<f3(p,4,8)<<endl;
p=f2;
cout<<f3(p,8,4)<<endl;
return 0;
}
搜索更多相关主题的帖子: int 函数指针 return 流程 std 
2008-01-13 12:51
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
得分:0 
谢谢楼上各位了,经过各位指点明白了不少,又查看了一些书,对函数指针比较了解了,但对其应用还不大会,要是应用函数指针自已写代码,肯定会还很多错误的!!!呵呵!

i like linux...
2008-01-13 22:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-197316-1-1.html




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

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