Sign in to follow this  
johns700

Declare enumeration in header file (C++)

Recommended Posts

johns700    122
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

Share this post


Link to post
Share on other sites
smitty1276    560
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. :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this