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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

enum in msvc++?

  • 18-08-2000 2: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