C++函数指针的问题

软件和网站开发以及相关技术探讨
回复
weihua2008
帖子: 448
注册时间: 2008-07-10 15:08

C++函数指针的问题

#1

帖子 weihua2008 » 2008-12-26 9:50

我从网上找了一个关于函数指针的例子
结果用g++调试出现问题
#include<iostream>
#include<string>
using namespace std;
int test(int);
int test2(int (*ra)(int),int);
int main(int argc,char **argv)
{
cout<<test<<endl;它给我个警告说funcparam2.cpp:8: warning: the address of ‘int test(int)’, will always evaluate as ‘true’,根本输出不了test函数的地址,撒回事?
typedef int(*fp)(int);
fp fpi;
fpi=test;
cout<<test2(fpi,1)<<endl;
cin.get();
return 0;
}
int test(int a)
{
return a - 1;
}
int test2(int (*ra)(int),int b)
{
int c=ra(10)+b;
return c;
}
chenwl
帖子: 509
注册时间: 2008-09-06 10:04

Re: C++函数指针的问题

#2

帖子 chenwl » 2008-12-26 12:54

可能和编译器有关吧
回复