这里是演示一个恼人问题的代码:
class A {
public:
A():
m_b(1),
m_a(2)
{}
private:
int m_a;
int m_b;
};
这是控制台 View 的输出:
make all
Building file: ../test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d" -MT"test.d" -o"test.o" "../test.cpp"
../test.cpp: In constructor 'A::A()':
../test.cpp:9: warning: 'A::m_b' will be initialized after
../test.cpp:8: warning: 'int A::m_a'
../test.cpp:3: warning: when initialized here
Finished building: ../test.cpp
问题是,在 Problems View 中,我会看到 3 个单独的警告(输出中包含警告词的行),而输出中确实有 4 行描述了一个问题。
有什么我想念的吗?
附加问题。也许它符合 Eclipse 精神,但有没有办法像大多数 IDE(例如 Visual Studio、emacs ...)一样使 Console View 可点击
谢谢 迪马
最佳答案
警告中有多行,因为每一行都引用不同的代码行。被警告的问题是 m_b
发生了什么这是在第 9 行声明的,因为 m_a
第 8 行在 m_b
之前声明是的,但这是由由您的初始化列表中发生的事情引起的,该列表从第 3 行开始。
使用 gcc,彼此不相关的警告可能会一个接一个地出现(即,一堆不相关的东西在 main
中都是错误的),因此 Eclipse 无法从输出中判断这些警告是否是单独的警告或都与同一问题相关。
关于c++ - Eclipse C++编译警告问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1218914/