0

My base class (State.h):

#pragma once
#include <Windows.h>
#define WIN32_LEAN_AND_MEAN
#include <gl\GL.h>
#include <gl\GLU.h>
#include "StateManager.h"

class State
{
public:
    virtual ~State();

    virtual void update(double dt){}
    virtual void render(){}
};

The derived class(State_Test.h):

#pragma once
#include "State.h"
class State_Test : public State
{
public:
    State_Test();
    ~State_Test();
};

The errors it gives are in a different class (StateManager.h):

#pragma once

#include "State.h"

#include <map>
#include <string>

class StateManager
{
public:
    StateManager();
    ~StateManager();

    std::map<std::string, State *> m_StateMap;//error C2976: 'std::map' :     too few template arguments | error C2065: 'State' : undeclared identifier | error C2059: syntax error: '>'
    std::string m_CurrentState;

    void AddState(std::string stateId, State *state);//error C2061: syntax error : identifier 'State'
    void ChangeState(std::string stateId);

};

Also there's this warning:

Warning 5   warning C4005: '_malloca' : macro redefinition  c:\program files (x86)\microsoft visual studio 12.0\vc\include\crtdbg.h 586 1 

Syntactically it looks correct, VS doesn't underline anything, and this code had worked before without error. I'm just wondering if anybody has seen this error before or knows what the cause of it is?

Dortimer
  • 619
  • 8
  • 25
  • First I'd try moving the #define WIN32_LEAN_AND_MEAN above the windows.h inclusion, it won't do much for if you define it after the #include. – Timo Geusch Apr 10 '15 at 20:38
  • Why does `state.h` need to include `statemanager.h`? Actually, the `State` class doesn't need any of those `#include` files; move them to the source file. – Thomas Matthews Apr 10 '15 at 21:20

1 Answers1

2

You have circular dependency problem: State.h includes StateManager.h, which includes State.h.

Since StateManager uses only pointer to State, remove this include and forward declare State:

#pragma once

//#include "State.h" -> remove this

#include <map>
#include <string>

class State; //-> add this

class StateManager
{
public:
    StateManager();
    ~StateManager();

    std::map<std::string, State *> m_StateMap;
    std::string m_CurrentState;

    void AddState(std::string stateId, State *state);
    void ChangeState(std::string stateId);
};
Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49