struct test{
int a=1111111;

}test;

vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structpp
struct.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 structpp
struct.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 here
const int a=11111111;
~~~~~~~~~~^~~~~~~~~~
1 warning and 1 error generated.
vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structpp
struct.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 here
static const int a=11111111;
~~~~~~~~~~~~~~~~~^~~~~~~~~~
1 error generated. vincentdeMacBook-Air:datasturte vincent$ g++ struct.cpp -o structpp
struct.cpp:4:12: error: non-const static data member must be initialized out of
line
static 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

warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]的更多相关文章

  1. 【转】forbids in-class initialization of non-const static member不能在类内初始化非const static成员

    转自:forbids in-class initialization of non-const static member不能在类内初始化非const static成员 今天写程序,出现一个新错误,好 ...

  2. C++ Data Member内存布局

    如果一个类只定义了类名,没定义任何方法和字段,如class A{};那么class A的每个实例占用1个字节的内存,编译器会会在这个其实例中安插一个char,以保证每个A实例在内存中有唯一的地址,如A ...

  3. DataTables warning : Requested unknown parameter '0' from the data source for row 0错误

    在做datatables的项目,从后台取得数据后,返回给datatables界面时会报下面的错误: DataTables warning : Requested unknown parameter ' ...

  4. Link static data in sql source control

    You can link data that doesn't change very often to SQL Source Control. This lets you commit data ch ...

  5. Effective C# 学习笔记(原则一:始终能的使用属性(property),而不是可直接访问的Data Member)

    原则一:始终能的使用属性(property),而不是可直接访问的Data Member    Always use properties instead of accessible data memb ...

  6. 3.1 Data Member的绑定

       文章开始提出了一段示例代码,并讨论了返回哪个x的问题.然后 a)   给出了我们普遍认为正确的回答,并肯定了这个想法: b)   提醒大家,这在以前的编译器实现中,并非正确. 在早期的实现中,首 ...

  7. 始终使用属性(Property),而不是字段(Data Member)

    1.始终使用属性(Property),而不是字段(Data Member) C# 属性已经晋升为一等公民,如果你的类中还有public的字段,Stop.访问属性和字段的方式是一样的,但是属性是用方法( ...

  8. [C++] static member variable and static const member variable

    static member variable[可读可写] 可以通过指针间接修改变量的值 static const member variable[只读] 压根就不可以修改变量的值,会报错

  9. warning MSB3162: 所选的“Microsoft Report Viewer 2012 Runtime”项需要“Microsoft.SqlServer.SQLSysClrTypes.11.0”。在“系统必备”对话框中选择缺少的系统必备组件,或者为缺少的系统必备组件创建引导程序包。

    warning MSB3162: 所选的“Microsoft Report Viewer 2012 Runtime”项需要“Microsoft.SqlServer.SQLSysClrTypes.11. ...

随机推荐

  1. ProjectManager Beta 2 项目管理器发布

    上次载Alpha阶段有一个可用版本Alpha 8也在这个博客发布了,传送:http://www.cnblogs.com/deali/p/ProjectManager.html ProjectManag ...

  2. Python之日期与时间处理模块(date和datetime)

    本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常需要用到日期与时间,如: 作为日志信息的内容输出 计算某个功能的执行时 ...

  3. LoadRunner 调用Dll完成加密解密

    LoadRunner里的函数比较少,没有MD5.Base64加密. 我们可以通过在C++里把一些加解密写成函数,供LR调用. DLL函数编写 C++里新建工程Class Library(此处是用VS2 ...

  4. jquery在Asp.net下实现ajax

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxTest ...

  5. PHP标准库(SPL)- SplDoublyLinkedList类(双向链表)

    class SplDoublyLinkedList implements Iterator, Traversable, Countable, ArrayAccess { const IT_MODE_L ...

  6. 微信小程序 JS动态修改样式

    微信小程序这个坑啊,js动态修改样式,我们并不能用js或者jq 轻轻松松一行代码搞定.或者用removeClass addClass 来修改样式. 以下是一种动态修改样式的方法,原理是绑定数据,然后动 ...

  7. PHP 数组处理

    一:PHP 定义数组: PHP 代码  不能再 空的位置 打字  会报错 定义数组  方式1 $cars=array("Volvo","BMW","T ...

  8. 分布式架构--Dubbo项目实战学习文档

    安装Dubbo注册中心(Zookeeper-3.4.6) 安装Dubbo管理控制台 Tomcat中部署web应用 ---- Dubbo服务消费者Web应用war包的部署 Dubbo监控中心的介绍与简易 ...

  9. PHP 中使用 Composer

    在线安装版本: http://www.phpcomposer.com/ 这个是国内的composer网站 thinkphp5自带了composer.phar组件,如果没有安装,则需要进行安装 以下命令 ...

  10. css之line-height

    行内框盒子模型1."内容区域"(content area)2."内联盒子"(inline boxes)3."行框盒子"(line boxes ...