我想为一个本身由一个 int 参数模板化的类 C 专门化一个模板方法。
我该怎么做呢?
template <int D=1>
class C {
static std::string foo () { stringstream ss; ss << D << endl; return ss.str();}
};
template <class X>
void test() { cout << "This is a test" << endl;}
template <>
template <int D>
void test<C<D> > () {cout << C<D>::foo() << endl;}
test() 的特化失败,出现“void test() 声明中的模板参数列表过多”。