为什么我在运行Boost代码时总是收到警告?

时间:2014-05-24 01:34:00

标签: c++ boost warnings

我注意到当我从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时我是否可能出错?

2 个答案:

答案 0 :(得分:2)

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

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

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

-isystem /path/to/boost

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

答案 1 :(得分:1)

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