【发布时间】:2013-02-21 17:41:03
【问题描述】:
我在 Dev C++ 中为我的 C++ 项目解析一个 XML 文件,并且我在 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;
它给了我这些错误:
no class template named `ptrdiff_t' in `std'
ISO C++ forbids declaration of `difference_type' with no type
no class template named `bidirectional_iterator_tag' in `std'
ISO C++ forbids declaration of `iterator_category' with no type
在出现这些错误之前,上面的代码如下:
typedef typename xml_node<Ch> value_type;
typedef typename xml_node<Ch> &reference;
typedef typename xml_node<Ch> *pointer;
typedef std:: ptrdiff_t difference_type;
typedef std:: bidirectional_iterator_tag iterator_category;
这给了我这样的嵌套名称说明符错误:
expected nested-name-specifier
`xml_node<Ch>' specified as declarator-id
two or more data types in declaration of `xml_node<Ch>'
expected `;' before "value_type"
在我进行解析的主文件中,我包含以下内容:
#include <iostream>
#include "rapidxml.hpp"
#include "rapidxml_iterators.hpp"
#include "rapidxml_print.hpp"
#include "rapidxml_utils.hpp"
#include <iterator>
#include <istream>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <streambuf>
#include <cstddef>
我已经在这个网站上搜索过类似的帖子,并且我已经关注了他们的 建议,但到目前为止,他们都没有解决我的问题。是 Dev C++ 还是我的代码有问题?谢谢
【问题讨论】:
-
请在此之前发布错误,以及您已经指定的任何包含文件。所有这些似乎对于诊断正在发生的事情是必要的。
-
@Kevin,我刚刚编辑了我的问题并包含了我以前的错误和包含的内容。希望这有帮助
-
你不需要
typename在任何 typedef 中。您没有使用从属名称。还是这些类型定义在模板中? -
是的,它们在模板内
-
我想我们至少需要一些你的类声明。如果您有理由不告诉我们,则不一定是所有内容,但是您在做什么和在哪里做事的方式“闻起来”有问题。还要看看你是否可以折叠你的错误。只包括几乎不需要的文件和行来编译具有相同错误消息的东西,然后发布。就像“没有这些行,它可以编译,但有它们,它会失败!”并给其余的。您应该能够将其简化为很少的几行。
标签: c++ xml-parsing tree compiler-errors rapidxml