Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带有模板类参数的模板类专门化_C++_Templates_Specialization - Fatal编程技术网

C++ 带有模板类参数的模板类专门化

C++ 带有模板类参数的模板类专门化,c++,templates,specialization,C++,Templates,Specialization,假设我有: template < typename T > class ClassA { void doTheStuff (T const * t); }; template < typename T > class ClassB { // Some stuff... }; 模板 甲级 { void doTheStuff(T const*T); }; 模板 B类 { //一些东西。。。 }; 我想为ClassB模板的所有实例专门化doTheStuf

假设我有:

template < typename T >
class ClassA 
{
    void doTheStuff (T const * t);
};

template < typename T >
class ClassB
{
    // Some stuff...
};
模板
甲级
{
void doTheStuff(T const*T);
};
模板
B类
{
//一些东西。。。
};
我想为ClassB模板的所有实例专门化doTheStuff方法,如下所示:

template <typename T>
void ClassA< ClassB< T > >::doTheStuff (ClassB< T > const * t)
{
    // Stuff done in the same way for all ClassB< T > classes
}
模板
void ClassA>:doTheStuff(ClassBconst*T)
{
//所有B类类都以相同的方式完成
}
当然,这是行不通的。遗憾的是我不知道我怎么能做到

使用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 *)'
错误C2244:'ClassA::doTheStuff':无法将函数定义与现有声明匹配
参见“ClassA::doTheStuff”的声明
定义
'void ClassA::doTheStuff(const ClassB*)'
现有声明
'void ClassA::doTheStuff(const T*)'
我发现这个帖子:

因此,我按照建议尝试了完整的类专门化,但也不起作用:

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
    }
};
模板
模板
类别A>
{
公众:
void doTheStuff(类b常数*b)
{
//所有B类类都以相同的方式完成
}
};
视频显示:

error C2910: 'ClassA<ClassB<U>>' : cannot be explicitly specialized
错误C2910:'ClassA':无法显式专门化
欢迎任何帮助


Floof。

删除额外的
模板
,它就会工作。

谢谢!它确实有效,我不知道为什么他们在另一个线程上有这个额外的模板。