Enum in header files

25,599

Solution 1

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.

Solution 2

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

Share:
25,599
drCoding
Author by

drCoding

I am relative new to programing games. I have worked in c++ for a long time.

Updated on February 10, 2020

Comments

  • drCoding
    drCoding about 4 years

    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