如何沉默 "whose type uses the anonymous namespace [-Werror]" gcc 版本 4.8.2

How to silence "whose type uses the anonymous namespace [-Werror]" gcc version 4.8.2

在我的一个项目的头文件中,inline 方法中包含以下行

typedef boost::archive::iterators::transform_width<boost::archive::iterators::binary_from_base64<      boost::archive::iterators::remove_whitespace<std::string::const_iterator>>, 8, 6> Base64ToBin;

当我用 gcc 4.8.2 编译时,出现以下错误:

error: ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >’ has a field ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >::’ whose type uses the anonymous namespace [-Werror]

我真的很努力但无法解决这个问题,而且从link1 and link2看来这是gcc版本较低的问题。有人可以建议如何消除此警告或克服它。我正在使用 -Werror 标志编译。

这看起来像是一个正确的警告。因为代码在 header 中,所以它将包含在多个文件中,但匿名命名空间对于每个文件都是唯一的。这意味着该类型在任何地方都没有相同的定义。

解决方法:将相关代码移动到.cpp文件中。