博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-exten...
阅读量:5295 次
发布时间:2019-06-14

本文共 1559 字,大约阅读时间需要 5 分钟。

struct test{

int a=1111111;

}test;

vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structppstruct.cpp:4:6: warning: in-class initialization of non-static data member is a      C++11 extension [-Wc++11-extensions]int a=11111111;     ^1 warning generated.

struct test{

const int a=1111111;

}test;

vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structppstruct.cpp:4:12: warning: in-class initialization of non-static data member is a      C++11 extension [-Wc++11-extensions]const int a=11111111;           ^struct.cpp:29:4: error: cannot assign to non-static data member 'a' with      const-qualified type 'const int'q.a=10;~~~^struct.cpp:4:11: note: non-static data member 'a' declared const hereconst int a=11111111;~~~~~~~~~~^~~~~~~~~~1 warning and 1 error generated.vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structppstruct.cpp:29:4: error: cannot assign to static data member 'a' with      const-qualified type 'const int'q.a=10;~~~^

struct test{

static int a=11111111;

}test;

 

struct.cpp:4:18: note: static data member 'a' declared const herestatic const int a=11111111;~~~~~~~~~~~~~~~~~^~~~~~~~~~1 error generated. vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structppstruct.cpp:4:12: error: non-const static data member must be initialized out of      linestatic int a=11111111;           ^ ~~~~~~~~1 error generated.

  同样问题:http://stackoverflow.com/questions/13662441/c11-allows-in-class-initialization-of-non-static-and-non-const-members-what-c

 

转载于:https://www.cnblogs.com/vincentqliu/p/6553258.html

你可能感兴趣的文章
Calendar类
查看>>
把word文档中的所有图片导出
查看>>
Spring 自动装配;方法注入
查看>>
浏览器的判断;
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
Oracle 初始化参数 二三事,随记
查看>>
三维凸包模板
查看>>
zoj 2432(最长递增上升子序列)
查看>>
uva 10791
查看>>
JD路径配置及myeclipse主题和提示设置
查看>>
codeforces Round #440 A Search for Pretty Integers【hash/排序】
查看>>
python的字典(dict)的键值对存储规则
查看>>
java cooki的使用
查看>>
more 分页显示文件内容
查看>>
ubuntu18 tensorflow cpu fast_rcnn
查看>>
PageHelper在Mybatis中的使用
查看>>
POJ 1742 Coins
查看>>
Spring Boot -- Start Up
查看>>
JS常用各种正则表达式(汇总)
查看>>
UVa1225 数数字
查看>>