程序无法编译 - 我做错了什么?

时间:2011-08-23 23:28:36

标签: c++ xml parsing

这只是一个简单的头文件,用于使用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 &copy) : 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 ++的新手。

2 个答案:

答案 0 :(得分:1)

我无法调试您的文件系统问题。但是,对我来说,对错误进行一些翻译并不困难。

编译说:

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’

编译器意味着:

  

帮助!
当你试图使用某些东西时,我没有找到你试图使用的东西 - 也就是说,我不知道任何名称空间“std”。你试图   从const XMLCh *构造一个XercesString,但我找不到一个可以接受它的构造函数。
  你把分号留在GraphHandler定义的末尾,所以我不知道如何理解你写的下一个东西。
  你将分号放在Character结构的函数末尾。

其他错误很可能是简单地没有声明正确的类型,但它们也可能是其他错误。没有你展示main.cpp的来源我不知道。

答案 1 :(得分:0)

如果您自己编译,那么您已经忘记了make install命令(如果您的make文件有一个)