代码在这里。编译器是VC++ 2012.奇怪!静态常量无符号不是类模板中的常量表达式?
template<class T> // Normal class is okay. But template has the problem.
class A
{
const static unsigned N = 2; // not okay
// enum {N = 2}; // this is okay
template<unsigned i> void Fun() {}
template<> void Fun<N>() {} // error C2975 not constant expression
};
为什么?谢谢。
摆脱N'的'和'使用乐趣<2>'你应该得到同样的错误,至少在GCC 4.8.1(我假设VS就会有他们,但你没有发布错误) 。这真的对你的问题的标题有影响。 – chris
@chris我纠正了我的问题。谢谢。 – user1899020