Bug 000111

When Created: 09/25/1996 11:52:56
Against DJGPP version: 2.00
By whom:
Abstract: C++ Post-increment operator error message, OK in C
This program will not compile as C++.  Compiler error for the "For (result=...) line is shown below.
When I change the iostream and cout to regular C code (i.e. printf) compile is OK.

                                   // Chapter 2 - Program 1
#include <iostream.h>

enum game_result {win, lose, tie, cancel};

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";

>gcc enum.cpp   -Wall -lgpp -o enum.exe
enum.cpp: In function `int main()':
enum.cpp:11: no post-increment operator for type

Note added: 09/26/1996 09:08:22
By whom:
After further work I have noticed that the problem in the FOR statement is the portion "result++". This statement compiles with a warning and executes if changed to "result=result+1".

Note added: 11/26/1996 05:03:15
By whom:
  My C++ reference book mentions: "A small but potentially important difference
between C and C++ is that in C, a character constant is automatically elevated
to an integer. In C++, it is not." It seems likely to me that this is the
problem; under C the compiler is treating the enumeration as an integer, so the
++ operator works, but under C++ it treats it as an enumeration, and no ++
operator is defined.
  I don't see this as being a problem. The point of making a variable an
enumeration rather than an integer is that it will be holding basically
nonlinear values. You would normally deal with such a variable by using an if
or switch statement, not by incrementing it.

Closed on 04/13/1999 08:00:52: Programmer's error, not a DJGPP bug.
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010