模板专业化 -> 'too few template-parameter-lists'

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

本文关键字:few template-parameter-lists too gt 专业化      更新时间:2023-10-16

我找不到这段代码有什么问题:

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

我一直得到:

"错误:模板参数列表太少"

在专业化之前缺少template<>

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