enum question.

This is a discussion on enum question. within the C++ Programming forums, part of the General Programming Boards category; I am going to write an enumerated type that identifies the suit of the jail cell. However, it should be ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    77

    enum question.

    I am going to write an enumerated type that identifies the suit of the jail cell. However, it should be from another class - Card.

    I tried to code it like that
    Code:
    enum card::suit; //an enumerated type (located in the Card ADT) that identifies the suit of the jail cell
    I think it is not going to work, can anyone gives me some suggest?

    Here is the code from card.h
    Code:
    #include <iostream>
    
    using namespace std;
    
    class Card
    {
    public:
    
        enum Rank
        {
            ACE,
            TWO,
            THREE,
            FOUR,
            FIVE,
            SIX,
            SEVEN,
            EIGHT,
            NINE,
            TEN,
            JACK,
            QUEEN,
            KING
        };
    
        enum Suit
        {
            SPADES,
            HEARTS,
            CLUBS,
            DIAMONDS
        };
    
        Card(); // Default constructor will initialize to Ace of Spades
        Card( Rank newRank, Suit newSuit );
    
        Rank getRank() const {return rank;}
        Suit getSuit() const {return suit;}
    
        void setRank( Rank newRank );
        void setSuit( Suit newSuit );
    
    private:
    
        Rank rank;
        Suit suit;
    };
    
    ostream& operator<<( ostream& os, const Card& card );
    appericate it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    Create a small program and try it. A small program, with one class, containing one enum and one member function shouldn't take more than 5 minutes to determine whether you have the right idea or not. If your experiment works, then it'll work in your main program as well.

    It's usually quicker to test what you think is right than ask for confirmation on a message board. If you are right, then you can move forward immediately.

    If on the other hand it doesn't work, then post your code and question, then we can help sort out the bugs in your understanding and/or the code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Isn't this the same question you posted last week?

    Also, as Salem suggested, whenever you are writing a program and you can't get a new concept to work, create another program to test the concept out. I have a project called TestStuffOut that is always ready for me to do just that--then I don't have to go through the hassle of creating a new project every time I want to test something.
    Last edited by 7stud; 05-01-2005 at 02:44 AM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    similar to, but not that one,
    i m working on a card game now.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    Thanks for help, but would you please give me an example problem that how i can test it. I can use this example for my future reference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 05:22 AM
  2. Question on Enum
    By markcls in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:19 AM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  4. Enum question
    By Bill 101 in forum C Programming
    Replies: 4
    Last Post: 10-31-2002, 12:33 AM
  5. enum question
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 12-30-2001, 12:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21