2

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

14
  • Are they in the same namespace? Commented Feb 9, 2012 at 23:39
  • I am not using a name space. Do I need a namespace Commented Feb 9, 2012 at 23:39
  • 4
    Would be useful if you could post more complete code. These pieces on their own don't appear to be incorrect, so something must be wrong at a different level in your code. Commented Feb 9, 2012 at 23:43
  • 1
    Sorry, should be more explicit. A lot of people here are really good programmers that can take 6 lines of code and figure out that hey, you're getting conflicts in the global namespace or some jazz like that. But for the rest of us mere mortals we often like to have compilable, testable code so that we can poke it and prod it until it works. At a minimum you might want to give the header including the enumeration declaration and the load_rc() function. Commented Feb 9, 2012 at 23:54
  • 1
    Sorry I will add all of the base.cpp, base.h, sm.cpp, cm.h Commented Feb 9, 2012 at 23:55

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Not a problem. If your compiler supports #pragma once, you can use it in place of your #ifndefs. Code will be less portable, though.
1

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

1 Comment

sm.h is included in base.cpp and base.h

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.