boost :: function的奇怪行为与函数指针

mka*_*aes 2 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
Run Code Online (Sandbox Code Playgroud)

我想知道为什么函数在与类型和typedef一起使用时表现不同,应该表示相同的类型.这对我来说不是问题,因为我只是不使用typedef,但我仍然很想知道为什么会有区别.
我使用的编译器是MSVC2010.

Luc*_*ton 6

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

typedef int function_type(Interface*,int,bool&);
function_type* p = 0; // Pointer to function here
boost::function<function_type> fn;
Run Code Online (Sandbox Code Playgroud)