2

Say I have :

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

template < typename T >
class ClassB
{
    // Some stuff...
};

I'd like to specialize the doTheStuff method for all instances of the ClassB template like this:

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 doesn't work. Shame is I don't know how I could do that.

With visual studio's 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: Templated class specialization where template argument is a template

So I tried the full class specialization as advised but it doesn't work either:

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 welcome !

Floof.

Community
  • 1
  • 1
F.L.
  • 559
  • 4
  • 11

1 Answers1

2

Remove the extra template<> and it will work.

Andrei Tita
  • 1,226
  • 10
  • 13
  • Thanks ! It does work, I don't know why they had this extra template <> on the other thread. – F.L. Dec 20 '12 at 11:04