类模板的明确专业化

时间:2016-06-01 12:41:25

标签: linux visual-c++

这是我的代码:

template <int T>
class Converter
{
public:
    static const int bin;
};

template<int T>
const int Converter<T>::bin = (T % 2 == 1) ? (10 * Converter<T / 2>::bin + 1) : (10 * Converter<T / 2>::bin);

template<>
const int Converter<1>::bin = 1;

我有主要的:

std::cout << "dec: 1" << "\tbin: " << Converter<1>::bin << "\n";

对于Windows上的Linux和CodeBlocks,此行正常运行。对于VS我有错误:

  

成员的明确专业化&#34; Converter :: bin [with T = 1]&#34;必须先于第一次使用()

我不知道,如何为VS的T = 1重写最后一个模板。有什么想法吗?

0 个答案:

没有答案
相关问题