我有一堂课
template <typename T>
class C
{
static const int K=1;
static ostream& print(ostream& os, const T& t) { return os << t;}
};
我想将 C 专门用于 int。
//specialization for int
template <>
C<int>{
static const int K=2;
}
我希望保留适用于 int 的默认打印方法,只需更改常量即可。对于某些专业,我想保持 K=1 并更改打印方法,因为没有 << 运算符。
我该怎么做呢?