Tutorial :C++ Why am I unable to use an enum declared globally outside of the class it was declared in?


Right now, my project has two classes and a main. Since the two classes inherit from each other, they are both using forward declarations. In the first object, right underneath the #include statement, I initialize two enums, before the class definition. I can use both enums just fine inside that class. However, if I try to use those enums in the other class, which inherits from the first one, I get an error saying the enum has not been declared. If I try to redefine the enum in the second class, I get a redefinition error.

I have even tried using a trick I just read about, and putting each enum in its own namespace; that didn't change anything.

Here's an example:

#ifndef CLASSONE_H  #define CLASSONE_H    namespace Player  {      enum Enum      {          One,          Two,      };  }    

Next Post »