我想定义没有类的模板变量,但 MSVC++ 不接受它,并且根据 C++ 标准在它周围搜索似乎是不正确的:
template<CharType> static CharType hexDigits[17];
template<> char hexDigits[17] = "0123456789ABCDEF";
template<> wchar_t hexDigits[17] = L"0123456789ABCDEF";
然后,这些专用变量将在(非专用)模板函数中使用。
所以我不得不这样写:
template<typename CharType> class dummyclass {
static CharType hexDigits[17];
};
template<> char dummyclass<char>::hexDigits[17] = "0123456789ABCDEF";
template<> wchar_t dummyclass<wchar_t>::hexDigits[17] = L"0123456789ABCDEF";
有什么方法可以在不定义虚拟类的情况下定义这两个变量?
另外, C++ 标准不允许第一段代码有什么好的理由吗?毕竟,类外的模板函数是允许的。