c++ - 指向对象的指针的未声明标识符 vector

标签 c++ undeclared-identifier

错误: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/

相关文章:

c++ - 如何确定非多态类型的混合模板的类型兼容性

c++ - std::begin 和 R 值

c - C 结构中未声明的标识符错误

c++ - 如何覆盖 GCC 的配置以进行包含搜索?

c++ - 内存型号 : Activation records

c++ - 可调用项,转发,右值和线程

c - OpenGL 链接错误

C# 7.0 Unity 游戏开发问题,来自 4.0 的标识符不再起作用

java - “堆栈”未声明的错误。 Java 到 C

swift - 在 TableView 中使用未解析的标识符 'section'