我认为我有循环依赖问题,不知道如何解决它...... 尽可能短: 我编码的东西就像一个HTML解析器。 我有一个main.cpp文件和两个头文件Parser.h和Form.h. 这些头文件容纳整个定义...(我懒得做相应的.cpp文件...循环依赖...如何解决?
Form.h看起来是这样的:
//... 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
和Parser.h外观像这样:
// 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
不知道这是否是重要的,但我在做MS构建的Visual Studio 2010旗舰版和 它抛出我 “分析器”:不是类或命名空间名称
如何解决这个问题? 谢谢!
解决方案:不要太懒惰;) – 2012-02-24 18:01:48
@ 500-InternalServerError::-)所以这意味着我必须分开定义和声明?它会有帮助吗? – Novellizator 2012-02-24 18:04:24
@Tomy:是的,没有分离它几乎是不可能的。 – 2012-02-24 18:07:00