delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/30/20:08:06

Newsgroups: comp.os.msdos.djgpp
From: malyon AT netcom DOT com (Roland Acton)
Subject: Re: enumerated types overloading
Message-ID: <malyonE4ty0K.HvH@netcom.com>
Organization: Netcom On-Line Services
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970128122351 DOT 10987T-100000 AT is> <32EF6DC7 DOT 153A AT byu DOT edu>
Date: Thu, 30 Jan 1997 16:33:56 GMT
Lines: 27
Sender: malyon AT netcom17 DOT netcom DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

cbird (cbird AT byu DOT edu) wrote:
: > enum alpha {a, b, c, d, e, f};
: > 
: > in my header and when I try something like:
: > 
: > alpha letter = a;
: > a++;
: > 
: > I get an error saying no postincrement operator defined or something
: > along those lines.

: the a++ sohuld be a letter++ up there.  I accidentally mistyped it when
: posting to this newsgroup (I know you can't increment a constant)  I get
: an error when incrementing letter 'cause it's of type alpha and there is
: no defined incrementor of that type.  My question is, how can I make it
: so.  I believe it has something to do with overloading the ++ operator,
: but I've never done that before in C++.

  First of all, you shouldn't be trying to increment an enumeration.
Enumerations are intended for sets of related items or concepts (such as
{yes, no} or {red, blue, green}), not for numerical ranges.
  That said, you should be able to increment a by using:

a = (alpha) (a + 1);

: Christian Bird
: cbird AT byu DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019