user3234091
user3234091

Reputation: 31

vector<class*> compiler error 2143, 4430, 2238

Hi everyone and thanks in advance for the help. I have the following class that throws an error on compiling where i declase a vector of pointers

I have an Engine class that I want to host multiple scenes objects stored in the vector sceneList and then pass which ever I want to render to a SceneBase pointer

#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;
};

Line throw three error codes for each of the following error codes 2143, 4430, 2238. Also, I have the following header that also implements a vector of pointers that do not throw any errors

#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;
};

On the Engine.h if i change vector scenesList; to std::vector scenesList; the error 2143 is not thrown but all the others are. Could anyone point what I am missing? and why this works on SceneBase.h and not in Engine.h?

Thanks

Upvotes: 1

Views: 152

Answers (1)

Mahmoud Fayez
Mahmoud Fayez

Reputation: 3459

Your two headers files SceneBase.h and Engine.h are including each other which is wrong. use forward declaration in the header files such that you have something like that:

in a.h

class b;

class a
{
// class a stuff goes here
}

in b.h

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

in the .cpp files you can include the files safely

Upvotes: 1

Related Questions