2
说我有:模板类专业化
template < typename T >
class ClassA
{
void doTheStuff (T const * t);
};
template < typename T >
class ClassB
{
// Some stuff...
};
我想专门的doTheStuff方法是这样的ClassB的模板的所有实例:
template <typename T>
void ClassA< ClassB<T> >::doTheStuff (ClassB<T> const * t)
{
// Stuff done in the same way for all ClassB<T> classes
}
当然,但,这是行不通的。耻辱是我不知道我该怎么做。
与Visual Studio的编译器,我得到:
error C2244: 'ClassA<T>::doTheStuff' : unable to match function definition to an existing declaration
see declaration of 'ClassA<T>::doTheStuff'
definition
'void ClassA<ClassB<T>>::doTheStuff(const ClassB<T> *)'
existing declarations
'void ClassA<T>::doTheStuff(const T *)'
我发现这个职位:Templated class specialization where template argument is a template
于是,我就满级的专业化的建议,但它不工作之一:
template <>
template < typename U >
class ClassA< ClassB<U> >
{
public:
void doTheStuff (ClassB<U> const * b)
{
// Stuff done in the same way for all ClassB<T> classes
}
};
可视为:
error C2910: 'ClassA<ClassB<U>>' : cannot be explicitly specialized
欢迎任何帮助!
Floof。
谢谢!它确实有效,我不知道为什么他们在另一个线程上有这个额外的模板。 –