当前时区 GMT+8, 现在时间是 2008-9-9 02:00 游客: 注册 登录 仅登录论坛 | 搜索 帮助


标题: 刚开始学c++,函数指针问题!
superhxl
中级会员
Rank: 3Rank: 3


UID 8918
精华 0
积分 942
帖子 392
阅读权限 30
注册 2002-12-22
来自 China
状态 离线
发表于 2006-12-26 09:07  资料  短消息  加为好友 
刚开始学c++,函数指针问题!

小弟最近刚开始学习c++,有一点不太清楚!以前学习C语言时,C里面有讲到函数的指针,感觉很方便!但是最近查了一些C++的资料,好像都没有提到函数指针问题,是不是C++不支持该功能了?把以前的程序输进去也不能编译通过,求解!如果不支持,应该怎样实现同样的功能,谢谢!注:
[code:1]#include <iostream>

int main()
{
    int max();

    int a,b,c;
    //指向函数的指针,该函数返回类型为整数
    int (*p)();

    std::cout<<"Pleanse enter two number:";
    std::cin>>a>>b;

    p=max;
    std::cout<<"the max is "<<(*p)(a,b);
}

int max(int x,int y)
{
    if ( x>y ) return x;
    return y;
}
[/code:1]gcc3.4编译不能通过





Once we dreamt that we were strangers. We wake up to find that we were dear to each other!
顶部
superhxl
中级会员
Rank: 3Rank: 3


UID 8918
精华 0
积分 942
帖子 392
阅读权限 30
注册 2002-12-22
来自 China
状态 离线
发表于 2006-12-26 15:35  资料  短消息  加为好友 
已经搞定了,呵呵!





Once we dreamt that we were strangers. We wake up to find that we were dear to each other!
顶部
 


Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
清除 Cookies - 联系我们 - 中国Linux公社 - WAP