首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一道关于函数指针的面试题解决方法

2012-02-08 
一道关于函数指针的面试题1.typedefvoid&foo(int,int)2.typedefvoid(&foo)(int,int)3.typedefint(*foo)(

一道关于函数指针的面试题
1.typedef   void   &foo(int,int);
2.typedef   void   (&foo)(int,int);
3.typedef   int   (*foo)(void);
4.typedef   int   *foo(void);

问这4个有什么区别,

我知道3是函数指针,别的都是什么意思啊

另外还有一个问题
void   foo(const   int   *arg);
void   foo(const   int   &arg);
这两个有什么区别呢,谢了

[解决办法]
1.typedef void &foo(int,int);
定义一个别名叫foo,foo可以用来定义一个函数
2.typedef void (&foo)(int,int);
定义一个别名叫foo,foo可以用来定义一个函数
3.typedef int (*foo)(void);
定义一个别名foo,foo可以用来定义一个函数指针
4.typedef int *foo(void);
定义一个别名叫foo,foo可以用来定义一个函数
[解决办法]
//typedef void &foo1(int,int);
typedef void (&foo2)(int,int);
typedef int (*foo3)(void);
typedef int *foo4(void);

#include <typeinfo>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
cout < <typeid(foo2).name() < <endl;
cout < <typeid(foo3).name() < <endl;
cout < <typeid(foo4).name() < <endl;

return 0;
}


test

[解决办法]
1.typedef void &foo(int,int);〈======编译不过去
2.typedef void (&foo)(int,int);〈=======函数的引用
3.typedef int (*foo)(void);〈=======函数指针
4.typedef int *foo(void);〈=======函数类型,返回int*类型参数无

热点排行