C++ 混合显式类专门化和类方法专门化?
所以我有一个类,它想要实例化两个类中的一个。我在标题中声明:C++ 混合显式类专门化和类方法专门化?,c++,templates,C++,Templates,所以我有一个类,它想要实例化两个类中的一个。我在标题中声明: template <class T> class MyClass { public: bool DoSomethingGeneric(); bool DoSomethingTSpecific(); }; 现在,让我猜个谜:我应该把显式专门化放在哪里?如果我将其放在模板定义之后(就像我通常对纯泛型类的专门化所做的那样),clang说: explicit specialization of 'MyClass<
template <class T>
class MyClass {
public:
bool DoSomethingGeneric();
bool DoSomethingTSpecific();
};
现在,让我猜个谜:我应该把显式专门化放在哪里?如果我将其放在模板定义之后(就像我通常对纯泛型类的专门化所做的那样),clang说:
explicit specialization of 'MyClass<ClassA>' after instantiation
这个对我来说有点神秘
有什么想法吗?如何实现显式类级专门化和显式方法专门化>C++标准<强>>7.7.3(5)显式专业化< /强>(强调矿山): 显式专用类模板的成员是 以与普通类成员相同的方式定义,并且不使用
模板
语法
例如:
template <> // specialization for classA
class MyClass<ClassA> {
public:
bool DoSomethingTSpecific(); // must be declared here
};
// template<> is not used here
bool MyClass<ClassA>::DoSomethingTSpecific() {
// ClassA-specific implementation
}
template//classA的专门化
类MyClass{
公众:
bool DoSomethingTSpecific();//必须在此处声明
};
//此处不使用模板
bool MyClass::DoSomethingTSpecific(){
//ClassA特定实现
}
演示:
无法重现重现与问题无关的重现。这一个复制了它:注意显式类专门化的添加。移动专业化会复制这两个错误。这个怎么样?哈!就这样!我知道你的答案,我会接受的。
no function template matches function template specialization 'DoSomethingTSpecific'
template <> // specialization for classA
class MyClass<ClassA> {
public:
bool DoSomethingTSpecific(); // must be declared here
};
// template<> is not used here
bool MyClass<ClassA>::DoSomethingTSpecific() {
// ClassA-specific implementation
}