C++: warning "will be initialized after [-Wreorder]

背景

使用GCC编译代码时遇到以下警告:

warning "will be initialized after [-Wreorder]

原因

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

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


https://stackoverflow.com/questions/1564937/gcc-warning-will-be-initialized-after
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++)?


猜你喜欢

转载自blog.csdn.net/u012348774/article/details/82354436