drCoding
drCoding

Reputation: 65

Enum in header files

I have enum declared in a header file called "sm.h"

enum GameStates
{
  STATE_NULL = 0,
  STATE_INTRO,
  STATE_TITLE,
  STATE_MAIN,
  STATE_EXIT
};

All it does is list the possible game states

However in the following line in "base.cpp":

stateID = STATE_INTRO;

The compiler says "STATE_INTRO was not declared in this scope". I have no idea what I am doing wrong. I know that I have included the header file right and I can go to its deceleration from the .cpp file. So why am I getting this error.

stateID = STATE_INTRO;

Is used in:

bool baseFunctions::load_rc()
{
 stateID = STATE_INTRO;

 currentState = new Intro();

 return true;
}

which defines a class function in a header file.

There are no global conflicts because it is the only enum in the whole program

Upvotes: 2

Views: 27156

Answers (2)

Joel Rondeau
Joel Rondeau

Reputation: 7586

From your link to your files, you have the following in both sm.h and base.h

#ifndef BASE_H_INCLUDED
#define BASE_H_INCLUDED

Change the one in sm.h to something like

#ifndef SM_H_INCLUDED
#define SM_H_INCLUDED

and I expect you'll be fine.

As it is, base.cpp loads base.h, then when it gets to sm.h the #ifndef is false, so it excludes everything in sm.h.

Upvotes: 4

Martin Beckett
Martin Beckett

Reputation: 96157

Most likely is that you aren't including "sm.h" in base.cpp

Upvotes: 1

Related Questions