I think I have a cyclic dependency issue and have no idea how to solve it….
To be as short as possible:
I am coding something like a html parser.
I have a main.cpp file and two header files Parser.h and Form.h.
These header files hold the whole definitions… (I’m too lazy to make the corresponding .cpp files…
Form.h looks like this:
//... standard includes like iostream....
#ifndef Form_h_included
#define Form_h_included
#include "Parser.h"
class Form {
public:
void parse (stringstream& ss) {
// FIXME: the following like throws compilation error: 'Parser' : is not a class or namespace name
properties = Parser::parseTagAttributes(ss);
string tag = Parser::getNextTag(ss);
while (tag != "/form") {
continue;
}
ss.ignore(); // >
}
// ....
};
#endif
and Parser.h looks like this:
// STL includes
#ifndef Parser_h_included
#define Parser_h_included
#include "Form.h"
using namespace std;
class Parser {
public:
void setHTML(string html) {
ss << html;
}
vector<Form> parse() {
vector<Form> forms;
string tag = Parser::getNextTag(this->ss);
while(tag != "") {
while (tag != "form") {
tag = Parser::getNextTag(this->ss);
}
Form f(this->ss);
forms.push_back(f);
}
}
// ...
};
#endif
Don’t know if it is important, but I’m doing the build in MS Visual Studio Ultimate 2010
and it throws me
‘Parser’ : is not a class or namespace name
How to solve this problem?
Thank you!
What you probably want to do here is leave the method declaration in the header like so
And define the method in a source file (i.e. a Form.cpp file) like so
That should resolve the cyclic dependency issue you’re seeing…