Chiko
Chiko

Reputation: 606

template specialization -> 'too few template-parameter-lists'

i can't find what's wrong with this code:

template <class T>
class B{
    T _t;
public:
    B(T t) : _t(t) {}
    void printHello();
};

template <class T>
void B<T>::printHello(){
    std::cout << "Hello";
}
void B<char*>::printHello(){
    std::cout <<"Good bye!";
}

I keep getting:

'error: too few template-parameter-lists'

Upvotes: 0

Views: 2371

Answers (1)

Prasoon Saurav
Prasoon Saurav

Reputation: 92864

template<> is missing before the specialization

template<>
void B<char*>::printHello(){
    std::cout <<"Good bye!";
}

Upvotes: 3

Related Questions