C ++ 11中的数组维度

时间:2018-09-19 15:22:48

标签: c++ arrays c++11 dimension

我已经在C ++ Primer中研究了数组的维数应该是const表达式,但是下面的代码编译并给出了所需的结果。为什么?

#include<iostream>
using namespace std;
int main()
{
unsigned int bufsize = 10;
int h[bufsize]={};
for(int i=0; i<=9; i++)
    cout<<h[i]<<endl;
}

但是,如果我添加以下内容:

constexpr int a = bufsize;

然后编译器显示错误,表示bufsize不是常数表达式,那么为什么程序要正确编译,否则如果数组的维数应该是常数表达式

0 个答案:

没有答案