错误:Cell.h 的第 12 行:“Actor”未声明的标识符。
如果我尝试在它上面转发声明,它说有一个重新定义。我该怎么办?
Actor.h:
#ifndef ACTOR_H
#define ACTOR_H
#include <iostream>
#include <vector>
#include <string>
#include "Cell.h"
using namespace std;
class Actor //Simple class as a test dummy.
{
public:
Actor();
~Actor();
};
#endif
单元格.h:
#include <iostream>
#include <string>
#include <vector>
#include "Actor.h"
#ifndef CELL_H
#define CELL_H
using namespace std;
class Cell // Object to hold Actors.
{
private:
vector <Actor*> test;
public:
Cell();
~Cell();
vector <Actor*> getTest();
void setTest(Actor*);
};
#endif
单元格.cpp:
#include "Cell.h"
#include <vector>
vector<Actor*> Cell::getTest() //These functions also at one point stated that
{ // they were incompatible with the prototype, even
} // when they matched perfectly.
void Cell::setTest(Actor*)
{
}
我还能做什么?
最佳答案
从 Actor.h
中删除 #include "Cell.h"
,您就可以开始了。
一般来说,在可能的地方优先使用前向声明,在必须的地方包含。我还将 Cell.h
中的 #include "Actor.h"
替换为前向声明:class Actor;
。
如果需要,您可以在 cpp
文件中包含标题。
关于c++ - 指向对象的指针的未声明标识符 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13198657/