У заголовка печати RapidXML есть неопределенные методы

Я возился с использованием 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 Заголовок Я вижу все вышеупомянутые функции, на которые ссылаются внутри функции print_node. Позже функции print_children, print_element_node и т. Д. Будут определены, и с первого взгляда все будет в порядке. Что я здесь не так делаю?

17

Решение

Для тех, кто приезжает сюда в поисках решения той же проблемы, у меня есть решение. Посмотрев на http://gcc.gnu.org/gcc-4.7/porting_to.html в разделе «Изменения в поиске имен» (согласно предложению n.m.) я изменил заголовок rapidxml_print.hpp, чтобы иметь следующее право перед объявлением функции 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.

52

Другие решения

И чтобы удалить неиспользуемые флаги в функции print_attributes, удалите слово flags в прототипе этой функции

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

и в своей декларации

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

По вопросам рекламы [email protected]