我有一个针对自动机的许多状态的泛型类.它声明如下:
#ifndef STATE_H_
#define STATE_H_
#include "Automat.h"
class State {
public:
virtual void readChar(char c, Automat* automat) = 0;
virtual ~State(){};
};
#endif /* STATE_H_ */
Run Code Online (Sandbox Code Playgroud)
我在eclipse中遇到这个错误:
此行有多个标记
我的自动贩卖机如下:
#ifndef Automat_H_
#define Automat_H_
#include "../../Scanner/src/IScanner.h"
#include "./States/State.h"
class Automat {
public:
int count;
State* current;
IScanner* scanner;
Automat(IScanner *s);
void readChar(char c);
void setState(State *s);
void error();
~Automat();
};
#endif /* Automat_H_ */
Run Code Online (Sandbox Code Playgroud)
最后实现了Automat,我将省略一些方法.
#include "Automat.h"
#include "./States/StartState.h"
Automat::Automat(IScanner *s) {
current = StartState::makeStartState();
scanner = s;
count = 0;
}
void Automat::readChar(char c) {
current->readChar(c, this);
}
Run Code Online (Sandbox Code Playgroud)
我不知道是什么原因引起的.我需要在界面中声明事物吗?为什么要转换参数?
谢谢大家.
两个标题都试图互相包含,这是不可能的.
幸运的是,类定义都不需要另一个的完整定义.每个只处理指向另一个的指针,只需要声明.所以更换
#include "Automat.h"
Run Code Online (Sandbox Code Playgroud)
同
class Automat;
Run Code Online (Sandbox Code Playgroud)
同样地State.