One more enum question

This is a discussion on One more enum question within the C++ Programming forums, part of the General Programming Boards category; I am creating an ADT named RowstackException which inside the class, It should contain a public enumerated typed named RowstackExceptions. ...

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

    One more enum question

    I am creating an ADT named RowstackException which inside the class, It should contain a public enumerated typed named RowstackExceptions. There will only be one value in the enumerated type: RowStackEmpty

    Since I don't use enum always, I don't have idea how to code for this, can anyone gives me some suggest.
    Here is what i code

    Code:
    enum RowStackExceptions;
    Does it like that?

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you're pretty close - you can find a short explanation of enum here

    hope that helps
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    what is that for the second link?

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    77
    Coz i am gonna to throw an exception when the stack doesn't have card

    So, for the code, Can I use that?

    Code:
    enum RowstackExceptions { RowstackEmpty };

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    In C++, you can create your own types with the 'class' keyword or the 'enum' keyword. Using the 'class' keyword, the following creates a type Card:
    Code:
    #include <iostream>
    using namespace std;
    
    class Card
    {
    
    private:
    	int x;
    	double y;
    
    public:
    	Card()
    	{
    		x=10;
    		y=25.5;
    	}
    
    	void display()
    	{
    		cout<<x<<endl
    			<<y<<endl;
    	}
    	
    };
    
    
    int main()
    {
            Card c;  //declare a variable of type card
    	c.display();
    	
    	return 0;
    }
    Using the 'enum' keyword, the following creates a type MyException:
    Code:
    #include <iostream>
    using namespace std;
    
    enum MyException
    {
    	exception1,
    	exception2,
    	exception3
    };
    
    int main()
    {
            MyException exc;   //create a variable of type MyException
    	exc = exception3;  //assign the variable one of the three allowed values
    	cout<<exc<<endl;   //shows that the allowed values are actually equivalent to int values
    	
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Quote Originally Posted by joenching
    Code:
    enum RowStackExceptions;
    Does it like that?
    By the way, you asked this same enum question before, and it was explained to you then why that statement is wrong.

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, 04:22 AM
  2. Question on Enum
    By markcls in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 08:19 AM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  4. Enum question
    By Bill 101 in forum C Programming
    Replies: 4
    Last Post: 10-30-2002, 11:33 PM
  5. enum question
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 12-29-2001, 11:04 PM

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