- 论坛徽章:
- 1
|
本帖最后由 asker160 于 2017-03-09 11:32 编辑
rt,一个很简单的程序,struct结构体里面定义了几个static变量,double类型的如果不同constexpr就不通过编译,而int类型的没有问题:
- #include<stdio.h>
- struct C{
- static int i;
- static const int j=1;
- static constexpr double d=1;
- static const double d1=1.0;
- };
- int main(){
- return 0;
- }
复制代码 编译会有错误:
- testStatic.cpp:6:25: error: in-class initializer for static data member of
- type 'const double' requires 'constexpr' specifier
- [-Wstatic-float-init]
- static const double d1=1.0;
- ^ ~~~
- testStatic.cpp:6:5: note: add 'constexpr'
- static const double d1=1.0;
- ^
- constexpr
- 1 error generated.
复制代码
这个到底是什么情况,int可以const,double就得constexpr,语言这么设计的原因是?
|
|