int (*foo())();如何使用?

xfxf20 2008-10-22 08:41:48
int (*foo())();

这个变量如何使用?
...全文
163 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xfxf20 2008-10-22
  • 打赏
  • 举报
回复
int (*foo())[];
再问一下,上面是什么意思,怎么用?
yyyapple 2008-10-22
  • 打赏
  • 举报
回复
foo 函数声明,无形参,返回类型为 指向无形参返回类型为int的函数指针
int test();
int (*foo())();

int test() {
printf("test\n");
return 0;
}
int (*foo())()
{
return test;
}
chlaws 2008-10-22
  • 打赏
  • 举报
回复
#include <iostream>
using std::cout;
using std::endl;

typedef int (*PF)();
PF foo();
int f();

PF foo()
{
cout << "foo test"<<endl;
int (*pf)();
pf = &f;
pf();
return pf;
}
int f()
{
cout <<"f test"<<endl;
return 1;
}

int main()
{
PF pfunc = foo();
pfunc();
return 0;
}
  • 打赏
  • 举报
回复
foo是一个函数声明
相当于
	typedef int(*F)();
F fo2();

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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