Chinaunix首页 | 论坛 | 博客
  • 博客访问: 361042
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 641
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-09 22:35
个人简介

不怕你失败,就怕你爬不起来。

文章分类

全部博文(50)

文章存档

2014年(50)

我的朋友

分类: C/C++

2014-09-10 09:30:19

构造函数时,初始化成员变量的顺序要与类声明中的变量顺序相对应,若不对应,则出现如题错误。解决方法就是按照顺序进行初始化。

      对这个问题,StackOverflow上也发生了讨论,以下摘录原文:

Question:

    I am getting a lot of these warnings from 3rd party code that I cannot modify. Is there a way to disable this warning or at least disable it for certain areas (like #pragma push/pop in VC++)?

Example:

list.h:1122: warning: `list >::node_alloc_' will be initialized after 
        list.h:1117: warning:   `allocator<LogOutput*> list<LogOutput*, allocator<LogOutput*> >::alloc_'



Best Answer :

Make sure the members appear in the initializer list in the same order as they appear in the class
Class C { int a; int b; C():b(1),a(2){} //warning, should be C():a(2),b(1) }
or you can turn -Wno-reorder
 
Another Answer:
	

For those using QT having this error, add this to .pro file QMAKE_CXXFLAGS_WARN_ON += -Wno-reorder

原文链接:


阅读(6964) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~