Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

enum in msvc++?

  • 18-08-2000 03:17PM
    #1
    Subscribers Posts: 1,911 ✭✭✭


    Declare result as an int and it will work.

    Draco.


Comments

  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    okay well that worked, and ta very much, but I shouldn't have had to do that should I?????


  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    When I tried to compile the following code in msvc++ 6 I got this error:
    C:\Windows\Desktop\tutprogs\Enum.cpp(14) : error C2676: binary '++' : 'enum game_result' does not define this operator or a conversion to a type acceptable to the predefined operator

    Alls Iwould like to know is how to get it sorted, ta
    // Chapter 2 - Program 1
    #include <iostream.h>
    
    enum game_result 
    {
      win, lose, tie, cancel
    };
    
    int main()
    {
      game_result result;
      enum game_result omit = cancel;
    
      for (result = win; result <= cancel; result++) 
      {
    	  if (result == omit) 
    		  cout << "The game was cancelled\n";
    	  else 
    	  {
    		  cout << "The game was played ";
    		  if (result == win)
    			  cout << "and we won!";
    		  if (result == lose)
    			  cout << "and we lost.";
    		  cout << "\n";
    	  }
      }
      return 0;
    }
    
    
    // Result of execution should be
    //
    // The game was played and we won!
    // The game was played and we lost.
    // The game was played
    // The game was cancelled
    

    [This message has been edited by Baz_ (edited 18-08-2000).]

    [This message has been edited by Baz_ (edited 18-08-2000).]


  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    Well, yeah, you should, because C++ doesn't consider enums to be ints, although C does. So, in the example above, you could not do normal integer arithmetic upon it. Your program would also have failed if you had tried
    game_result result;
    result = 1;
    


Advertisement