【发布时间】:2012-10-13 15:24:43
【问题描述】:
我可以像这样在 cpp 中定义一个专门的函数...
// 标题
template<typename T>
void func(T){}
template<>
void func<int>(int);
// cpp
template<>
void func<int>(int)
{}
如何在 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);
};
// cpp
template<>
void A<int>::func(int)
{}
【问题讨论】:
-
@Pukku 这涉及非模板类中方法的特化,这实际上与独立函数的特化相同(如我上面的工作示例中所示)。我问的是如何在 cpp 的专用 class 中定义一个方法。
标签: c++ visual-studio templates template-specialization