Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

wyrd

Working with enums.

This topic is 5317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an enum; enum SUITS { DIAMONDS, HEARTS, SPADES, CLUBS } And a member variable as follows; SUITS m_suit; The m_suits member variable is obviously set to the cards suit; m_suit = DIAMONDS; The problem; I''m trying to use the m_suit member variable as also an index lookup for displaying graphics. The index, just like the suits, range from 0-3. However, when I suit m_suit, I get some insane integer value like 235133423. When I use just a straight enum const value (DIAMONDS for example), I get the appropriate integer value. Is there any way to get the const value (DIAMONDS etc) out of my member variable m_suit which is of enum SUITS?

Share this post


Link to post
Share on other sites
Advertisement
If you assigned m_suit correctly, you would get a value between 0 and 3. Thus, you''re not assigning m_suit correctly. Maybe it''s uninitialized? Or shadowed by a local variable? Or maybe you''re pulling m_suit out of a bad/deleted object?

Share this post


Link to post
Share on other sites
Hmm, looks like that was the case. This is what I initially had as the constructor;


CCard::CCard(CCard::SUIT suit, CCard::FACE face)
: m_suit(suit), m_face(face)
{

}


I changed it to this, and everything worked;


CCard::CCard(CCard::SUIT suit, CCard::FACE face)
{
m_suit = suit;
m_face = face;
}


What was wrong with my first constructor? I thought I could initialize any values doing that (even value types)

[edited by - wyrd on January 25, 2004 2:32:30 PM]

Share this post


Link to post
Share on other sites
I don''t know, i think it should have worked. But I''ve never declared parameters explicitly within a class scope like you do (esp. when its the same class).

Try:
CCard::CCard(SUIT suit, FACE face): m_suit(suit), m_face(face){}

I don''t know, it''s just a shot in the dark.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!