You won't be able to define an enum
externally. In C++11 you can forward declare an enum
, however:
enum class Items: char;
... and later define it:
enum class Items: char {
PAC = 'C', GHOST = '@', FRUIT = 'o', POINTS = '.', WALL = '#', EMPTY = ' ', UNDEFINED = '+'
};
Note, however, that you can use the enumerator tags only where the definition was seen.
Based on your comment about multiple definitions, you don't have include guards in your header and the same header gets included multiple times. That is, seems you could have a header something like this:
// items.h
#ifndef INCLUDED_ITEMS
#define INCLUDED_ITEMS
enum Items { ... };
#endif
From the looks of it, you are trying to fold the representation of the game into into the definition of their names. That probably doesn't work too well, especially as they may change appearance (you might want to have PAC
alternate between C
and O
, for example). Most likely the actual code will talk about these names and you'll have the in multiple places. Just use an enum
to define the different items not defining any value for them and define their representation elsewhere:
enum Items { PAC, GHOST, FRUIT, POINTS, WALL, EMPTY, UNDEFINED };
extern char ItemDisplay[];
// elsewhere
char ItemDisplay[] = { 'C', '@', 'o', '.', '#', ' ', '+' };
... and then just use ItemDisplay[item]
whenever you need to draw an item
.