0

For example :

namespace MYGAMESTATE {
    enum class GameState {
        GAME
    };
}

How would I forward declare this enum in another file, since it is in a namespace?

Would it be one of these?

extern enum class MYGAMESTATE::GameState;
extern enum class GameState;
enum class GameState;
enum class MYGAMESTATE::GameState;
Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696
expl0it3r
  • 323
  • 1
  • 7
  • Does this answer your question? [How to forward declare a class which is in a namespace](https://stackoverflow.com/questions/19001700/how-to-forward-declare-a-class-which-is-in-a-namespace) – kmdreko Jul 24 '20 at 21:04
  • 1
    Why do want to forward-declare it in the first place? What are you trying to achieve by that? (It doesn't work for a reason, and while it can be made to work, I doubt you actually need it) – SergeyA Jul 24 '20 at 21:06
  • 1
    Since you are not providing a *storage type*, you cannot forward declare the enum. If it had a storage type, you could do `namespace MYGAMESTATE { enum class GameState : int; }` – Eljay Jul 24 '20 at 21:06
  • 2
    You can't. C++ just forbids this because it's pointless. Just include the header file with the declaration of the enum where you need it. – Zefick Jul 24 '20 at 21:07
  • What do you mean storage type @Eljay – expl0it3r Jul 24 '20 at 23:42
  • @SergeyA I'd like to hide as much code as possible in my header (PImpl) – expl0it3r Jul 24 '20 at 23:43
  • @kmdreko Thank you so much – expl0it3r Jul 24 '20 at 23:43
  • *q.v.* [enumeration declaration](https://en.cppreference.com/w/cpp/language/enum) – Eljay Jul 24 '20 at 23:51

0 Answers0