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<SceneBase> scenesList; to std::vector<SceneBase> 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

Recommended Answers

All 3 Replies

Error codes are not universal. Those are error codes your compiler happens to use. Other compilers do things differently, so don't quote error codes; tell us what the actual error is.

What are the errors, and on what lines are they?

On the Engine.h if i change vector<SceneBase> scenesList; to std::vector<SceneBase> scenesList; the error 2143 is not thrown but all the others are.

That one is because vector is part of the std namespace, so to use it you either call it as std::vector, or you put using namespace std; at the top (but please DO NOT EVER EVER DO THAT IN A HEADER FILE - it is a very bad habit), or you put using std::vector; somewhere before trying to use vector.

Thanks Moschops for pointing out the different meaining of error codes on different compilers, I'm using VS2013.

On the errors, it looks like they were because I'm including the Engine.h in the Scene.h file and I'm including the SceneBase.h in the Engine.h file. I removed SceneBase.h line 8 to the SceneBase.cpp file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.