iam*_*ind 10 c++ templates compiler-errors constexpr c++11
constexpr int get () { return 5; }
template<int N> struct Test {};
int main ()
{
int a[get()]; // ok
Test< get() > obj; // error:'int get()' cannot appear in a constant-expression
}
Run Code Online (Sandbox Code Playgroud)
我用ideone编译了这段代码.并且想知道为什么它会给出编译错误.是constexpr不允许函数作为template参数,还是编译器中的错误?
编辑:更改const int get()为int get()
此外,还有一个与ideone的错误是,如果你删除constexpr然后仍然声明一个数组是允许的!我认为这是一个C99功能.