我正在使用 Visual Studio 11 beta,我很好奇在我的类中存储 std::function 对象时出现的编译错误。
typedef std::function<void (int, const char*, int, int, const char*)> MyCallback;
在我的课堂上,
MyCallback m_callback;
这编译得很好。如果我在列表中再添加一个参数,它就会失败。
typedef std::function<void (int, const char*, int, int, const char*, int)> MyCallback;
失败是:
>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(535): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1> f:\development\projects\applications\my.h(72) : see reference to class template instantiation 'std::function<_Fty>' being compiled
1> with
1> [
1> _Fty=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(536): error C2504: 'type' : base class undefined
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (int,const char *,int,int,const char *,int)
1> ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C2146: syntax error : missing ';' before identifier '_Mybase'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(539): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
这是一个动态链接库,它正在准备数据以传递给另一个应用程序。我当然可以重新设计数据的格式,以便可以用更少的参数传递它,但我想知道为什么我看到了这个限制?
切换回 c 风格的函数指针,
typedef void (*MyCallback)(int, const char*, int, int, const char*, int);
似乎工作正常。