C++11 STL constexpr关键字

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

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

float a[square(9)];

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

 

 

 

posted @ 2020-05-08 22:10  啸傲风月  阅读(148)  评论(0编辑  收藏  举报