作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
g++ -Wall 选项包括 -Wreorder。该选项的作用如下所述。我不清楚为什么有人会关心(尤其是在 -Wall 中默认打开它)。
-Wreorder (C++ only) Warn when the order of member initializers given in the code does not match the order in which they must be executed. For instance: struct A { int i; int j; A(): j (0), i (1) { } }; The compiler will rearrange the member initializers for i and j to match the declaration order of the members, emit-ting a warning to that effect. This warning is enabled by -Wall.
最佳答案
考虑:
struct A {
int i;
int j;
A() : j(0), i(j) { }
};
现在 i
被初始化为某个未知值,而不是零。
另外,i
的初始化可能会产生一些副作用,这对顺序很重要。例如
A(int n) : j(n++), i(n++) { }
关于c++ - g++ -Wreorder 的意义何在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1828037/
我是一名优秀的程序员,十分优秀!