gpt4 book ai didi

c++ - RapidXML 打印头有未定义的方法

转载 作者:IT老高 更新时间:2023-10-28 21:59:22 36 4
gpt4 key购买 nike

我在我的一个项目中一直在使用 RapidXML。一切都很顺利,直到我决定用它来写出 xml。我的代码或多或少如下:

//attempt to open the file for writing
std::ofstream file(fileName.c_str());
if (!file.is_open())
return false; //the file didn't open

xml_document<> doc;
//creates the contents of the document...
//...
//...

//write the document out to the file
file << doc; //if I remove this line it compiles...but I kinda need this line to output to the file
file.close();

在编译时出现以下错误:

In file included from ../Engine/xmlfileloader.cpp:12:0:
../Engine/include/rapidxml_print.hpp: In instantiation of 'OutIt rapidxml::internal::print_node(OutIt, const rapidxml::xml_node<Ch>*, int, int) [with OutIt = std::ostream_iterator<char, char, std::char_traits<char> >; Ch = char]':
../Engine/include/rapidxml_print.hpp:390:57: required from 'OutIt rapidxml::print(OutIt, const rapidxml::xml_node<Ch>&, int) [with OutIt = std::ostream_iterator<char, char, std::char_traits<char> >; Ch = char]'
../Engine/include/rapidxml_print.hpp:403:9: required from 'std::basic_ostream<Ch>& rapidxml::print(std::basic_ostream<Ch>&, const rapidxml::xml_node<Ch>&, int) [with Ch = char]'
../Engine/include/rapidxml_print.hpp:414:31: required from 'std::basic_ostream<Ch>& rapidxml::operator<<(std::basic_ostream<Ch>&, const rapidxml::xml_node<Ch>&) [with Ch = char]'
../Engine/xmlfileloader.cpp:400:13: required from here
../Engine/include/rapidxml_print.hpp:115:17: error: 'print_children' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:169:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:120:17: error: 'print_element_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:242:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_element_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:125:17: error: 'print_data_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:208:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_data_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:130:17: error: 'print_cdata_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:219:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_cdata_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:135:17: error: 'print_declaration_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:298:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_declaration_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:140:17: error: 'print_comment_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:321:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_comment_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:145:17: error: 'print_doctype_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:339:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_doctype_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit
../Engine/include/rapidxml_print.hpp:150:17: error: 'print_pi_node' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
../Engine/include/rapidxml_print.hpp:361:22: note: 'template<class OutIt, class Ch> OutIt rapidxml::internal::print_pi_node(OutIt, const rapidxml::xml_node<Ch>*, int, int)' declared here, later in the translation unit

对我来说没有意义的是为什么它会以这种方式中断。查看 rapidxml_print.hpp header ,我看到上面提到的所有函数都在 print_node 函数中引用。后来定义了print_children、print_element_node等函数,一看就ok了。我在这里做错了什么?

最佳答案

对于那些来这里寻找相同问题的解决方案的人,我有一个解决方案。看完后http://gcc.gnu.org/gcc-4.7/porting_to.html在“名称查找更改”下(根据 n.m. 的建议)我将 rapidxml_print.hpp header 更改为在 print_node 函数声明之前具有以下内容(在我的文件中,我在第 104 行之后插入了这个):

template<class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags);

template<class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

template<class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);

它现在可以很好地使用 GCC 编译,并带有一个警告,因为显然 int flags 在 print_attributes 函数中未使用。

关于c++ - RapidXML 打印头有未定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14113923/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com