c++ - 警告 : Wlogical-not-parentheses

标签 c++ g++ warnings

我遇到了几天的问题。

我在编译我的程序时收到此警告。

In member function 'void CClientManager::RESULT_SAFEBOX_LOAD(CPeer*, SQLMsg*)':
661:25: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
        if (!dwSkillVnum > 120)
                         ^

还有一个警告:

661:25: warning: comparison of constant '120' with boolean expression is always false [-Wbool-compare]

我想提一下,这两个警告是在我上g++5.1.0之后出现的 在我使用 g++4.2 之前,我有这个警告。 那么我该如何解决这个问题。

这是我的文件:http://pastebin.com/fWYYmXsH

最佳答案

operator!() 的优先级高于 operator>(),因此您可以有效地将 !dwSkillVnum 转换为 bool 并将其与整数值进行比较。

要按照警告中的说明正确放置括号:

 if (!(dwSkillVnum > 120))
   // ^                 ^

关于c++ - 警告 : Wlogical-not-parentheses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30556317/

相关文章:

c++ - 代码在 g++ 中运行完美,但在 Xcode 中运行不完美 - 找不到文件

compiler-construction - 这是 F# 编译器错误吗? #3

c - 警告 : assignment makes pointer from integer without a cast [-Wint-conversion]

mysql - 无法解析来自服务器的 JSON 数据。这是由使用 group by 时 Zend 框架中的 JSON 格式错误引起的

c# - 哪些是了解 C#、ASP.NET、LINQ、SQL、C++、Ruby、Java、Python 最新信息的最佳博客?

c++ - 如何向 lambda 函数添​​加属性?

c++ - GNU g++ 4.9.2 中的重载 endl 编译问题

c++ - Eclipse 中的 Crypto++ 未定义引用

c++ - 从 C++ 中的函数返回数组

c++ - 如何在不指定Unix 中所有C 编译器位置的情况下指定一个程序配置文件的位置?