c++ - vector <类*> 编译器错误 2143、4430、2238

标签 c++ vector

大家好,在此先感谢您的帮助。我有以下类在编译时抛出错误,其中我声明了一个指针 vector

我有一个 Engine 类,我想托管存储在 vector sceneList 中的多个场景对象,然后将我想要渲染的对象传递给 SceneBase 指针

#pragma once

#include "Matrix3D.h"
#include "SceneBase.h"
#include <vector>

class Engine
{
public:
    static float deltaTime;

    Engine();
    ~Engine();

    void Init(int argc, char* argv[]);
    void Run();

    /* Forward declared GLUT callbacks registered by main. */
    static void Display();
    static void Update();
    static void Keyboard(unsigned char c, int x, int y);
    static void Resize(int width, int height);
    static Matrix3D perspective;

private:
    //static SceneBase *scene;
    static float previousTime;  
    vector<SceneBase*> scenesList;
};

行抛出三个错误代码,分别为以下错误代码 2143、4430、2238。 此外,我还有以下 header ,它还实现了一个不会引发任何错误的指针 vector

#pragma once

#include "OpenGLRenderer.h"
#include "BaseObject.h"
#include "TextureManager.h"
#include <vector>
#include <iostream>
#include "Engine.h"
#include "Matrix3D.h"

using namespace std; 

class SceneBase
{
public:
    SceneBase();
    virtual ~SceneBase();

    virtual void Init() = 0;
    virtual void Draw() = 0;
    virtual void Update() = 0;

protected:
    //List holding all objects in scene
    vector<BaseObject*> list;

    OpenGLRenderer rendererGL;
    TextureManager textureManager;
};

在 Engine.h 上,如果我更改 vector 场景列表;到 std::vector 场景列表;不会抛出错误 2143,但会抛出所有其他错误。谁能指出我所缺少的?为什么这适用于 SceneBase.h 而不是 Engine.h?

谢谢

最佳答案

您的两个头文件 SceneBase.hEngine.h 相互包含,这是错误的。在头文件中使用前向声明,这样你就有了类似的东西:

在啊

class b;

class a
{
// class a stuff goes here
}

在 b.h

class a;
class b
{
// class b stuff goes here
}

.cpp 文件中,您可以安全地包含这些文件

关于c++ - vector <类*> 编译器错误 2143、4430、2238,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22124977/

相关文章:

c++ - 运行时系统如何在已编译的二进制文件上支持 "GC"?

c++ - 通用引用 : Cannot convert parameter from 'int' to 'int &&'

c++ - 在指针 vector 中添加非重复值的最有效方法

c++在std::vector中存储逗号分隔的int的最快方法是什么

android - 在 ImageView 中设置 Vector Drawable 导致应用程序在旧 SDK 中崩溃

c++ - 如何在 C++ 中输出这些符号

c++ - 如何检查对象是否为常量?

c++ - Visual Studio C++ 2010 项目内链接错误

memory - 我可以将设备中的 cudaMemcpy 直接转换为主机 STL 向量吗?

c++ - 试图读取充满对象的 vector 的访问冲突