Declare enumeration in header file (C++)

Started by
0 comments, last by smitty1276 15 years, 9 months ago
Hey, I'm wondering how you go about using enumerations in a header file. I have tried it this way but recieve 'error C2065: undeclared identifier'. /* --- Header File --- */ //card.h #ifndef CARD_H #define CARD_H class Card { public: enum rank {}; }; #endif /* --- Implementation File --- */ //card.cpp #include "stdafx.h" #include "card.h" using namespace std; enum Card::rank { ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN = 10, JACK = 10, QUEEN = 10, KING = 10}; /* --- Application File --- */ //game.cpp #include "stdafx.h" #include "card.h" using namespace System; using namespace std; int main(array<System::String ^> ^args) { enum rank myRank; myRank = ACE; return 0; } Any help would be greatly apppreciated. Cheers
Advertisement
Out of curiosity, why are you wanting to define the enum in the C++ file, rather than just doing it in the header? In any case, read this.

The right search term actually turns up some useful info on google. Forward declarations of enums is not a feature of standard C++, though it appears that many compilers will let you do it. I would just avoid it if I were you. :-)

This topic is closed to new replies.

Advertisement