【问题标题】:Program Will Not Compile - What am I doing wrong?程序无法编译 - 我做错了什么?
【发布时间】: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 &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++ 新手。

【问题讨论】:

  • 文件本身存在吗?
  • /usr/include/xercesc/ContentHandler.hpp 存在吗?从源代码编译,你可能没有安装头文件,或者configure 可能需要一些额外的选项来将 .h/.hpp 文件放置在正确的位置
  • 你能把ls -al /usr/include/xercesc的结果贴出来吗?
  • 更新了输出。现在找到了文件。
  • 然而,其他一切都不起作用。这是为什么呢?

标签: c++ xml parsing


【解决方案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 的来源,我无法知道。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多