C++ 将在 [-Wreorder] 之后初始化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30364585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 13:45:45  来源:igfitidea点击:

will be initialized after [-Wreorder]

c++g++

提问by Irinel Iovan

When I compile my files I get this warning :

当我编译我的文件时,我收到此警告:

In file included from AsyncSQL.cpp:8:0:
AsyncSQL.h: In constructor 'CAsyncSQL::CAsyncSQL()':
AsyncSQL.h:192:10: warning: 'CAsyncSQL::m_iCopiedQuery' will be initialized after [-Wreorder]
   int    m_iCopiedQuery;
      ^

Here is my AsyngSQL.H http://pastebin.com/u72kyuq7So what am I doing wrong?

这是我的 AsyngSQL.H http://pastebin.com/u72kyuq7那么我做错了什么?

回答by SU3

The problem is the order in which you initialize members in the initializer list on line 22,

问题是你在第 22 行初始化列表中初始化成员的顺序,

_SQLResult(): pSQLResult(NULL), uiNumRows(0),
              uiAffectedRows(0), uiInsertID(0)

These should appear in the same order as they appear in the class definition. For example:

它们的出现顺序应与它们在类定义中出现的顺序相同。例如:

class test {
  test(): foo(1), bar(2) { }
  int  foo;
  long bar;
};