简体   繁体   English

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

[英]Program Will Not Compile - What am I doing wrong?

This is just a simple header file used to parse XML with the Xerces Parser. 这只是一个简单的头文件,用于使用Xerces Parser解析XML。 I'm banging my head trying to figure this one out, but for whatever reason, the compiler is complaining about things which shouldn't be an issue. 我正竭尽全力试图弄清楚这一点,但是出于任何原因,编译器都在抱怨那些本不应该成为问题的东西。 I need a second reference to look this over and tell me what's happening. 我需要第二个参考资料来仔细查看并告诉我发生了什么事。

#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

Here is my execution file: 这是我的执行文件:

#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();
}

Here's my output: 这是我的输出:

    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’

My xercesc directory DOES exist in the paths given. 我的xercesc目录确实存在于给定的路径中。 I compiled XercesC from source, and I have no idea what I'm doing. 我从源代码编译了XercesC,但我不知道自己在做什么。 I'm also new to C++. 我也是C ++的新手。

I can't debug your filesystem issues. 我无法调试您的文件系统问题。 It would, however, be not difficult for me to do some translation of the errors. 但是,对我来说,对错误进行一些翻译并不困难。

Compiler says: 编译器说:

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’

Compiler means: 编译器的意思是:

Help! 救命!
When you tried to use something, I didn't find the thing you attempted to use- ie, I don't know of any namespace "std". 当您尝试使用某些东西时,我没有找到您尝试使用的东西-即,我不知道任何名称空间“ std”。
You tried to construct a XercesString from a const XMLCh*, but I couldn't find a constructor that could take that. 您试图从const XMLCh *构造XercesString,但是我找不到可以接受该构造器。
You left the semicolon off the end of the GraphHandler definition, so I don't know how to understand the next stuff you wrote. 您将分号放在了GraphHandler定义的末尾,所以我不知道如何理解您编写的下一篇文章。
You put semicolons at the end of functions of the Character struct. 您将分号放在Character结构的函数末尾。

The other errors could well be a simple lack of having the right types declared, but they could also be other errors. 其他错误很可能只是缺少声明正确类型的简单错误,但也可能是其他错误。 I can't know without you showing the source of main.cpp. 如果您不显示main.cpp的源代码,我将无法知道。

如果您自己编译,则make忘记了make install命令(如果您的make文件只有一个)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM