【问题标题】:Why am I always getting warnings when running Boost code?为什么我在运行 Boost 代码时总是收到警告?
【发布时间】:2014-05-24 01:33:59
【问题描述】:

我注意到当我从 Boost 网站运行代码示例时收到大量警告。比如这个程序:

#include <cassert>
#include <string>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/filtering_stream.hpp>

namespace io = boost::iostreams;

int main()
{
    using namespace std;

    string                 result;
    io::filtering_ostream  out(io::back_inserter(result));
    out << "Hello World!";
    out.flush();
    std::cout << result;
}

这些是我得到的警告(我已经取出了大部分的血和内脏):

warning: declaration of 'close' shadows a member of 'this' [-Wshadow]
warning: declaration of 'ptr' shadows a member of 'this' [-Wshadow]
warning: declaration of 'close' shadows a member of 'this' [-Wshadow]
warning: declaration of 'next' shadows a member of 'this' [-Wshadow]
warning: declaration of 'component_type' shadows a member of 'this' [-Wshadow]
warning: declaration of 'close' shadows a member of 'this' [-Wshadow]
warning: declaration of 'component_type' shadows a member of 'this' [-Wshadow]
warning: declaration of 'next' shadows a member of 'this' [-Wshadow]
warning: declaration of 'close' shadows a member of 'this' [-Wshadow]
warning: declaration of 'next' shadows a member of 'this' [-Wshadow]
warning: declaration of 'close' shadows a member of 'this' [-Wshadow]

为什么会这样?有没有可能是我在安装 Boost 时做错了什么?

【问题讨论】:

    标签: c++ boost warnings


    【解决方案1】:

    这可能只是意味着编译器实施了更严格的警告。

    如果您的编译器版本/平台受支持,上游将(通常)修复这些编译器的代码。

    您通常可以通过执行以下操作来隐藏系统标头的警告:

    -isystem /path/to/boost
    

    (即代替-I /path/to/boost

    【讨论】:

    • 你知道我可以在哪里找到和了解这些很酷的编译器选项的教程吗?
    • 很遗憾。不,这只是积累的知识。不过有this
    【解决方案2】:

    不只是你。其他人也有reported这个问题。不过你的代码很好。

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 2013-10-04
      • 2012-04-07
      • 2012-06-24
      • 2011-10-24
      相关资源
      最近更新 更多