Program Will Not Compile - What am I doing wrong?
This is just a simple header file used to parse XML with the Xerces Parser. 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 ©) : 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 typ开发者_运维技巧es in declaration of ‘main’
My xercesc directory DOES exist in the paths given. I compiled XercesC from source, and I have no idea what I'm doing. I'm also new to 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- 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.
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.
If you compiled yourself you make have forgot the make install
command (if your make file had one)
精彩评论