【发布时间】:2011-08-23 23:28:36
【问题描述】:
这只是一个简单的头文件,用于使用 Xerces Parser 解析 XML。我正在努力解决这个问题,但无论出于何种原因,编译器都在抱怨不应该成为问题的事情。我需要第二个参考来查看这个并告诉我发生了什么。
#include "xerces_string.h"
using namespace std;
#ifndef CHARACTER_H
#define CHARACTER_H
struct Character
{
XercesString m_Name;
public:
Character();
Character(const Character ©) : m_Name(copy.m_Name) {
};
Character(const XMLCh *wstring) : m_Name(wstring) {};
virtual ~Character() {};
};
class GraphHandler : public DefaultHandler {
XercesString m_Name;
std::vector<Character> m_List;
public:
virtual void start_document();
virtual void end_document();
virtual void start_element(
const XMLCh * const uri,
const XMLCh * const localname,
const XMLCh * const qname,
const Attributes& attributes
);
virtual void end_element(
const XMLCh * const uri,
const XMLCh * const localname,
const XMLCh * const qname
);
virtual void characters(
const XMLCh * const chars,
const unsigned int length
);
}
#endif
这是我的执行文件:
#include </usr/include/xercesc/sax2/SAX2XMLReader.hpp>
#include </usr/include/xercesc/sax2/XMLReaderFactory.hpp>
#include </usr/include/xercesc/sax2/ContentHandler.hpp>
#include </usr/include/xercesc/sax2/DefaultHandler.hpp>
#include </usr/include/xercesc/sax2/Attributes.hpp>
#include </usr/include/xercesc/util/PlatformUtils.hpp>
#include <stdio.h>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include "character.h"
#include "xerces_string.h"
int main(int argc, char* argv[])
{
//initialize the XML library
XMLPlatformUtils::Initialize();
XMLPlatformUtils::Terminate();
}
这是我的输出:
In file included from main.cpp:15:
character.h:6: error: expected unqualified-id before ‘using’
character.h: In constructor ‘Character::Character(const XMLCh*)’:
character.h:18: error: no matching function for call to ‘XercesString::XercesString(const XMLCh*&)’
xerces_string.h:5: note: candidates are: XercesString::XercesString()
xerces_string.h:5: note: XercesString::XercesString(const XercesString&)
character.h: At global scope:
character.h:24: error: expected class-name before ‘{’ token
character.h:26: error: ISO C++ forbids declaration of ‘vector’ with no type
character.h:26: error: expected ‘;’ before ‘<’ token
character.h:37: error: ISO C++ forbids declaration of ‘Attributes’ with no type
character.h:37: error: expected ‘,’ or ‘...’ before ‘&’ token
character.h:24: error: new types may not be defined in a return type
character.h:24: note: (perhaps a semicolon is missing after the definition of ‘GraphHandler’)
main.cpp:18: error: two or more data types in declaration of ‘main’
我的 xercesc 目录确实存在于给定的路径中。我从源代码编译了 XercesC,但我不知道我在做什么。我也是 C++ 新手。
【问题讨论】:
-
文件本身存在吗?
-
/usr/include/xercesc/ContentHandler.hpp存在吗?从源代码编译,你可能没有安装头文件,或者configure可能需要一些额外的选项来将 .h/.hpp 文件放置在正确的位置 -
你能把
ls -al /usr/include/xercesc的结果贴出来吗? -
更新了输出。现在找到了文件。
-
然而,其他一切都不起作用。这是为什么呢?