程序不会编译-我做错了什么

Program Will Not Compile - What am I doing wrong?

本文关键字:错了 什么 编译 程序      更新时间:2023-10-16

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

我无法调试您的文件系统问题。然而,对我来说,对这些错误做一些翻译并不困难。

编译器说:

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的源代码我就不知道了。

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