Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带有函数指针的boost::函数的奇怪行为_C++_Boost - Fatal编程技术网

C++ 带有函数指针的boost::函数的奇怪行为

C++ 带有函数指针的boost::函数的奇怪行为,c++,boost,C++,Boost,我在玩弄boost::function的时候偶然发现了以下问题 typedef int(*IFnPtr2)(Interface*,int,bool&); IFnPtr2 p = NULL; boost::function<int(Interface*,int,bool&)> fn; // this is fine boost::function<IFnPtr2> fn2; // this gives me a compile error typedef

我在玩弄boost::function的时候偶然发现了以下问题

typedef int(*IFnPtr2)(Interface*,int,bool&);
IFnPtr2 p = NULL;
boost::function<int(Interface*,int,bool&)> fn; // this is fine
boost::function<IFnPtr2> fn2; // this gives me a compile error
typedef int(*IFnPtr2)(接口*,int,bool&);
ifnptr2p=NULL;
boost::函数fn;//这很好
boost::函数fn2;//这给了我一个编译错误
我想知道为什么函数在与类型和应该表示同一类型的typedef一起使用时表现不同。这对我来说不是问题,因为我只是不使用typedef,但我仍然很好奇为什么会有不同。

我使用的编译器是MSVC2010。

使用函数类型作为模板参数,以
boost::function
,而不是函数指针类型:

typedef int函数类型(接口*,int,bool&);
函数类型*p=0;//指向此处函数的指针
boost::函数fn;
typedef int function_type(Interface*,int,bool&);
function_type* p = 0; // Pointer to function here
boost::function<function_type> fn;