问题
In one of my project's header file, the following line is included in a inline
method
typedef boost::archive::iterators::transform_width<boost::archive::iterators::binary_from_base64< boost::archive::iterators::remove_whitespace<std::string::const_iterator>>, 8, 6> Base64ToBin;
When I compile this with gcc 4.8.2 I'm getting the following error:
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]
I'm really hitting hard but could not resolve this issue, also from the link1 and link2 it looks like it is an issue with lower version of gcc. Can somebody suggests how to silence this warning or get over with that. I'm using -Werror flag compilation.
回答1:
This looks like a correct warning. Because the code is in a header, it will be included from multiple files but the anonymous namespace is unique for every file. That means the type doesn't have the same definition everywhere.
Solution: move the relevant code to a .cpp file.
来源:https://stackoverflow.com/questions/37722850/how-to-silence-whose-type-uses-the-anonymous-namespace-werror-gcc-version-4