How to specialize a generic enum in Swift?

In C++, how do I globally use an enum in a multi-file project?

  • I have an enum declared globally in main.cpp like this... enum STATE {TITLE, LEVEL} state; The player class in player.cpp uses it...When I compile, I obviously get this error because player.cpp doesn't know that STATE exists since it's in main.cpp... player.cpp:68: error: ‘state’ was not declared in this scope player.cpp:68: error: ‘TITLE’ was not declared in this scope player.cpp:71: error: ‘LEVEL’ was not declared in this scope player.cpp:75: error: ‘LEVEL’ was not declared in this scope But when I try to declare it using extern in my global.h file, I get this... global.h:17: error: use of enum ‘STATE’ without previous declaration global.h:17: error: a storage class can only be specified for objects and functions In file included from player.cpp:1: I've tried extern enum STATE and extern STATE state...Nothing seems to work...What's the correct way to do this?

  • Answer:

    EDIT: You need to remove the enum list declaration from every file except in the header file, otherwise you will get that error The header file contains the declaration, the .cpp files contain the implementation Place the enumerated list inside the header file (the .h file), then it will automatically be included in any of the .cpp files which references to the header file

Adam at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.