自C++11起,constexpr可用来让表达式核定于编译期,例如

constexpr int square(int x){
    return x*x;
}

float a[square(9)];

cout<<"size="<<sizeof(a)/sizeof(a[0])<<endl;
 

 

 

C++11 STL constexpr关键字

 

相关文章: