【问题标题】:compile rapidxml under linux with g++linux下用g++编译rapidxml
【发布时间】:2010-09-30 13:13:12
【问题描述】:

下面的简单程序不能用gcc 4.4.3编译

#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
#include "rapidxml_iterators.hpp"

int main()
{
  return 0;
}

编译产生以下错误:

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
..........

我做错了什么?

【问题讨论】:

    标签: g++ compilation rapidxml


    【解决方案1】:

    这些错误是由 rapidxml_iterators.hpp 标头引起的。对于常规的 xml 解析,似乎不需要包含此标头。显然,其中定义的迭代器无论如何都不是真正可用的。它可能仍在开发中。另见here

    【讨论】:

      【解决方案2】:

      rapidxml_iterators.hpp 有问题。您必须将其更改为:

      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;
      

      【讨论】:

        【解决方案3】:

        简单案例的简单解决方案

        您实际上并不需要rapidxml_iterators.hpp,而是进行了完整性检查,对吧?

        解决方案:仅#include 您实际需要的标头。

        这是一般规则。 #include'ing 一切都像是吃得太多:它使情况变得又胖又慢。

        相比之下,只包括你需要的:

        • 让您了解您的实际代码依赖性,
        • 有助于保护您免受命名空间污染和偶尔的名称冲突,有时甚至是可移植性问题,
        • 当您开始将应该分开的东西弄乱时提醒您。

        如果你真的需要rapidxml_iterators.hpp

        至此,问题大概解决了。如果你真的需要rapidxml_iterators.hpp,它确实有问题(看起来这个特定的错误是Microsoftism)。此问题和其他问题于 2010 年 2 月在 http://sourceforge.net/p/rapidxml/bugs/10/ 上报告,建议的解决方案与 @user437634 的不同,截至 2013 年 7 月,该问题仍存在于当前版本中。

        【讨论】:

          猜你喜欢
          • 2013-07-21
          • 1970-01-01
          • 2018-07-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-16
          • 2014-03-14
          • 1970-01-01
          相关资源
          最近更新 更多