循环依赖关系..如何解决
cyclic dependency ... how to solve?
我认为我有一个循环依赖性问题,不知道如何解决它。。。。尽量简短:我正在编写类似于html解析器的代码。我有一个main.cpp文件和两个头文件Parser.h和Form.h。这些头文件包含整个定义。。。(我懒得制作相应的.cpp文件…
表单.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 Ultimate 2010中进行构建它把我扔了出去"Parser":不是类或命名空间名称
如何解决这个问题?非常感谢。
您可能想在这里做的是将方法声明像一样留在头中
class Form {
public:
void parse (stringstream& ss);
// ....
};
并在源文件(即Form.cpp文件)中定义方法,如
#include "Form.h"
#include "Parser.h"
void parse (stringstream& ss) {
properties = Parser::parseTagAttributes(ss);
string tag = Parser::getNextTag(ss);
while (tag != "/form") {
continue;
}
ss.ignore(); // >
}
这应该可以解决您所看到的循环依赖性问题。。。
- 停止在头中以词法内联的方式定义成员函数。在源文件中定义它们
- 现在,当您需要转发声明时,您可以利用它们(这里没有)
相关文章:
- 运行同一解决方案的另一个项目的项目
- Project Euler问题4的错误解决方案
- Ardunio UNO解决了多个重叠的定时器循环
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 两个文件使用彼此的功能-如何解决
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 在java中解决这段代码时面临循环中的问题
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 难以理解某些人解决IOI问题的源代码
- visual c++,如何获取解决方案目录中的代码
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 节俭并发:未解决的外部问题
- IpOpt拒绝解决不受约束的问题
- 如何解决这个超硬恒星的创造问题
- 循环无限运行C++解决骑士之旅问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- C++Matching Brackets 2解决方案不起作用
- 在 ubuntu3 上C++ goto 定义有什么解决方案吗16.04?
- 为什么一个程序被拒绝为可以通过过载解决来解决的模糊程序