我创建了一个模板类,并将 T 作为默认类型参数传递。但是,这会导致编译失败。任何人都可以解释会发生什么?谢谢!
PS。我使用的编译器是VS2012。
#include <functional>
using namespace std;
template <typename T = void()>
struct delegate
{
typedef function<T> function_t;
function_t f;
};
int main()
{
delegate<> d;
return 0;
}
编译器输出:
1>.\Microsoft Visual Studio 11.0\VC\include\functional(554): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (__cdecl *)(void)
1> ]
1> test.cpp(12) : see reference to class template instantiation 'std::function<_Fty>' being compiled
1> with
1> [
1> _Fty=void (__cdecl *)(void)
1> ]
1> test.cpp(17) : see reference to class template instantiation 'delegate<>' being compiled
1>.\Microsoft Visual Studio 11.0\VC\include\functional(555): error C2504: 'type' : base class undefined
1>.\Microsoft Visual Studio 11.0\VC\include\functional(558): error C2027: use of undefined type 'std::_Get_function_impl<_Tx>'
1> with
1> [
1> _Tx=void (__cdecl *)(void)
1> ]
1>.\Microsoft Visual Studio 11.0\VC\include\functional(558): error C2146: syntax error : missing ';' before identifier '_Mybase'
1>.\Microsoft Visual Studio 11.0\VC\include\functional(558): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int