gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:17:36 25 4
gpt4 key购买 nike

这只是一个简单的头文件,用于使用 Xerces 解析器解析 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’

编译器意味着:

Help!
When you tried to use something, I didn't find the thing you attempted to use- i.e., I don't know of any namespace "std".
You tried to construct a XercesString from a const XMLCh*, but I couldn't find a constructor that could take that.
You left the semicolon off the end of the GraphHandler definition, so I don't know how to understand the next stuff you wrote.
You put semicolons at the end of functions of the Character struct.

其他错误很可能只是缺少正确的类型声明,但它们也可能是其他错误。如果你不显示 main.cpp 的源代码,我就不知道了。

关于c++ - 程序无法编译——我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7168731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com