Dav*_*vid 12 c++ templates template-specialization visual-studio
我可以在cpp中定义一个专门的函数,就像这样......
//标题
template<typename T>
void func(T){}
template<>
void func<int>(int);
Run Code Online (Sandbox Code Playgroud)
// cpp
template<>
void func<int>(int)
{}
Run Code Online (Sandbox Code Playgroud)
如何在cpp中的专用类中定义方法?像这样(这不起作用,我得到error C2910: 'A<int>::func' : cannot be explicitly specialized)......
//标题
template<typename T>
struct A
{
static void func(T){}
};
template<>
struct A<int>
{
static void func(int);
};
Run Code Online (Sandbox Code Playgroud)
// cpp
template<>
void A<int>::func(int)
{}
Run Code Online (Sandbox Code Playgroud)
在.cpp文件中使用以下语法:
void A<int>::func(int)
{
}
Run Code Online (Sandbox Code Playgroud)
这是Visual C++有点特色.
有关详细信息,请参阅MSDN C2910错误说明:
由于在Visual Studio .NET 2003中完成的编译器一致性工作,也会生成此错误:对于代码将在Visual Studio .NET 2003和Visual Studio .NET的Visual Studio .NET版本中有效,删除模板<>.