Template class specialization with template class parameter

Let's say I have:

template < typename T > class ClassA { void doTheStuff (T const * t); }; template < typename T > class ClassB { // Some stuff... }; 

I would like to specialize the doTheStuff method for all instances of the ClassB template as follows:

 template <typename T> void ClassA< ClassB< T > >::doTheStuff (ClassB< T > const * t) { // Stuff done in the same way for all ClassB< T > classes } 

But of course this does not work. Shame, I do not know how I could do this.

With a visual studio compiler, I get:

  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 *)' 

I found this post: Private specialization of a class where the template argument is a template

So, I tried specializing in the whole class, as I advised, but it also does not work:

 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 } }; 

Visual says:

 error C2910: 'ClassA<ClassB<U>>' : cannot be explicitly specialized 

Any help is appreciated!

Floof.

+2
c ++ templates specialization
source share
1 answer

Remove the extra template<> and it will work.

+2
source share

All Articles