1

我正在开发一个 c++ 项目,我想在其中使用 rapidxml 库。该库可以在这里找到:http : //rapidxml.sourceforge.net/ 我下载了这个(4 个源代码文件 .hpp),并且能够使用 CodeBlocks IDE 在我的 Windows 机器上编译该项目。

但是,当我尝试在学校的 linux 机器上构建它时,它显示以下错误消息并且无法成功编译

我不确定问题是什么以及如何避免这些错误/警告。

/mydirectory/rapidxml.hpp: In constructor 'rapidxml::parse_error::parse_error(const char*, void*)':
/mydirectory/rapidxml.hpp:78:13: error: declaration of 'where' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:78:13: error: declaration of 'what' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:10:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*, std::size_t)':
/mydirectory/rapidxml.hpp:722:9: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*)':
/mydirectory/rapidxml.hpp:731:9: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*, std::size_t)':
/mydirectory/rapidxml.hpp:752:9: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*)':
/mydirectory/rapidxml.hpp:761:9: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In constructor 'rapidxml::xml_node<Ch>::xml_node(rapidxml::node_type)':
/mydirectory/rapidxml.hpp:902:13: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_node<Ch>::type(rapidxml::node_type)':
/mydirectory/rapidxml.hpp:1066:9: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:11:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml_utils.hpp: In constructor 'rapidxml::file<Ch>::file(const char*)':
/mydirectory/rapidxml_utils.hpp:40:20: error: declaration of 'size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml_utils.hpp: In constructor 'rapidxml::file<Ch>::file(const char*) [with Ch = char]':
/projectFolder/VmapXmlParser.cpp:29:46:   instantiated from here
/mydirectory/rapidxml_utils.hpp:40:40: error: declaration of 'size' shadows a member of 'this' [-Werror=shadow]
In file included from /mydirectory/VmapXmlParser.h:10:0,
                 from /projectFolder/VmapXmlParser.cpp:1:
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_node<Ch>::first_node(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:36:55:   instantiated from here
/mydirectory/rapidxml.hpp:936:23: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:936:23: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_node<Ch>::next_sibling(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:41:35:   instantiated from here
/mydirectory/rapidxml.hpp:1004:23: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1004:23: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_attribute<Ch>* rapidxml::xml_node<Ch>::first_attribute(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:48:60:   instantiated from here
/mydirectory/rapidxml.hpp:1025:28: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1025:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_attribute<Ch>* rapidxml::xml_attribute<Ch>::next_attribute(const Ch*, std::size_t, bool) const [with Ch = char, std::size_t = unsigned int]':
/projectFolder/VmapXmlParser.cpp:48:97:   instantiated from here
/mydirectory/rapidxml.hpp:856:28: error: declaration of 'name_size' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:856:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In constructor 'rapidxml::xml_node<Ch>::xml_node(rapidxml::node_type) [with Ch = char]':
/mydirectory/rapidxml.hpp:1365:41:   instantiated from 'rapidxml::xml_document<Ch>::xml_document() [with Ch = char]'
/projectFolder/VmapXmlParser.cpp:30:30:   instantiated from here
/mydirectory/rapidxml.hpp:901:9: error: declaration of 'type' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2114:17: error: switch missing default case [-Werror=switch-default]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2043:24: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_pi(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2107:48:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1889:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1899:29: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_comment(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2123:57:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1790:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_cdata(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2134:55:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2015:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_doctype(Ch*&) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2146:57:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:1817:25: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:1834:25: error: switch missing default case [-Werror=switch-default]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*, std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:2047:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:721:14: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_document<Ch>::parse_node_attributes(Ch*&, rapidxml::xml_node<Ch>*) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2053:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2243:28: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp:2053:13:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:2276:29: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*, std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:1910:17:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_pi(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2107:48:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:751:14: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void* rapidxml::memory_pool<Ch>::allocate_aligned(std::size_t) [with Ch = char, std::size_t = unsigned int]':
/mydirectory/rapidxml.hpp:419:65:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:618:69: error: cast from 'char*' to 'rapidxml::memory_pool<char>::header*' increases required alignment of target type [-Werror=cast-align]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::name(const Ch*) [with Ch = char]':
/mydirectory/rapidxml.hpp:426:21:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:730:14: error: declaration of 'name' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'void rapidxml::xml_base<Ch>::value(const Ch*) [with Ch = char]':
/mydirectory/rapidxml.hpp:433:21:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::memory_pool<Ch>::allocate_node(rapidxml::node_type, const Ch*, const Ch*, std::size_t, std::size_t) [with Ch = char, std::size_t = unsigned int]'
/mydirectory/rapidxml.hpp:2040:69:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
/mydirectory/rapidxml.hpp:760:14: error: declaration of 'value' shadows a member of 'this' [-Werror=shadow]
/mydirectory/rapidxml.hpp: In member function 'Ch rapidxml::xml_document<Ch>::parse_and_append_data(rapidxml::xml_node<Ch>*, Ch*&, Ch*) [with int Flags = 0, Ch = char]':
/mydirectory/rapidxml.hpp:2228:21:   instantiated from 'void rapidxml::xml_document<Ch>::parse_node_contents(Ch*&, rapidxml::xml_node<Ch>*) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2059:17:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_element(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:2090:49:   instantiated from 'rapidxml::xml_node<Ch>* rapidxml::xml_document<Ch>::parse_node(Ch*&) [with int Flags = 0, Ch = char]'
/mydirectory/rapidxml.hpp:1404:68:   instantiated from 'void rapidxml::xml_document<Ch>::parse(Ch*) [with int Flags = 0, Ch = char]'
/projectFolder/VmapXmlParser.cpp:31:32:   instantiated from here
4

1 回答 1

1

您正在使用带有严格选项的 GCC,这些选项会将某些(或全部)警告消息变成错误。

示例-这是错误:-

rapidxml.hpp: In constructor 'rapidxml::parse_error::parse_error(const char*, void*)':
rapidxml.hpp:78:13: error: declaration of 'where' shadows a member of 'this'
[-Werror=shadow]
rapidxml.hpp:78:13: error: declaration of 'what' shadows a member of 'this'
[-Werror=shadow]

...这是代码

class parse_error: public std::exception
{
public:
    //! Constructs parse error
    parse_error(const char *what, void *where)
        : m_what(what)
        , m_where(where)
    {
    }

“问题”是 GCC 认为代码可能是错误的,因为what并且where被用作构造函数中的参数名称 - 但它们也被定义为基类的成员函数。( std::exception)。

这是完全有效的 C++ 并且可以正常工作。GCC 只是被配置为超级挑剔。您需要添加选项-Wno-error=shadow以停止将这些警告视为错误。

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

于 2014-02-11T20:52:23.347 回答