g ++ -Wreorder的意义是什么? [英] What's the point of g++ -Wreorder?
本文介绍了g ++ -Wreorder的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
g ++ -Wall选项包括-Wreorder。此选项的作用如下所述。这是不明显的,为什么有人会关心(特别是足以打开在默认情况下在-Wall)。
The g++ -Wall option includes -Wreorder. What this option does is described below. It is not obvious to me why somebody would care (especially enough to turn this on by default in -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
初始化为某个未知值,而不是零。
Now i
is initialized to some unknown value, not zero.
或者, i
的初始化可能有一些副作用,例如
Alternatively, the initialization of i
may have some side effects for which the order is important. E.g.
A(int n) : j(n++), i(n++) { }
这篇关于g ++ -Wreorder的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文