Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

enum in msvc++?

Options
  • 18-08-2000 3:17pm
    #1
    Subscribers Posts: 1,911 ✭✭✭


    Declare result as an int and it will work.

    Draco.


Comments

  • Registered Users 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 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