开发者

compile rapidxml under linux with g++

The following simple program can't be compiled with gcc 4.4.3

#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
#include "rapidxml_ite开发者_StackOverflow社区rators.hpp"

int main()
{
  return 0;
}

Compile produces following errors:

rapidxml_iterators.hpp:21: error: expected nested-name-specifier
rapidxml_iterators.hpp:21: error: invalid declarator before ‘value_type’
rapidxml_iterators.hpp:22: error: expected nested-name-specifier
rapidxml_iterators.hpp:22: error: invalid declarator before ‘&’ token
..........

What I am doing wrong?


These errors are caused by the rapidxml_iterators.hpp header. It seems including this header is not necessary for regular xml parsing. Apparently, the iterators defined in there are not really usable anyway. It might be something still under development. See also here.


The rapidxml_iterators.hpp have some problem with it. You have to change it to this:

typedef xml_node<Ch> value_type;
typedef xml_node<Ch> &reference;
typedef xml_node<Ch> *pointer;
typedef typename std::ptrdiff_t difference_type;
typedef typename std::bidirectional_iterator_tag iterator_category;


Simple solution for simple case

You don't actually need rapidxml_iterators.hpp but were doing a sanity check, right ?

Solution: only #include the headers you actually need.

It's a general rule. #include'ing everything is like eating too much : it turns the situation fat and slow.

By contrast, including only what you need:

  • keeps you aware of your actual code dependency,
  • helps keeping you safe from namespace pollution and the occasional name clashes and sometimes even portability issues,
  • alerts you when you are starting to mess together things that should be kept separated.

If you really need rapidxml_iterators.hpp

At this point, the problem is probably solved. If you really need rapidxml_iterators.hpp, it's indeed buggy (looks like this particular error is a Microsoftism). This problem and others were reported on February 2010 on http://sourceforge.net/p/rapidxml/bugs/10/ with suggested solutions different from @user437634's, still open and present in current release as of July 2013.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜