🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: de.comp.lang.c++
Article #743

Re: enums

#743
From: Karl-Heinz Krause
Date: Mon, 06 Nov 1995 18:46
28 lines
1148 bytes
Am 3. Nov. 1995 schrieb Benjamin Baermann
(benni@dares.rbi.informatik.uni-frankfurt.de):

> Hallo!

> Mein Compiler weigert sich enums implizit nach int zu konvertieren. Das
> ist ja einerseits irgendwie korrekt, andererseits doch aber hochgradig
> unpraktisch, da dann so schoene Konstrukte, wie:

> const int maxcolor = 3;
> enum color {blue, white, green};

> for(i=0;i=maxcolor;i++){
> 	draw(i);
> }

Die korrekte C++-gerechte Version wäre wohl:

	enum color {blue, white, green};
	inline color operator++(color &c,int) 
	{ color tmp=c; c = color(c+1); return tmp; }

	for (color i=blue; i<=green; i++) draw(i);

Zugegebenermaßen ziemlich aufwendig. 


Karl-Heinz Krause
Technical Details
Message-ID: <47lon8$ktb@news00.btx.dtag.de>
Path: arc1-ca.pugleaf.net!news00.btx.dtag.de!not-for-mail!Krause
References: <47cqj5$d70@zeus.rbi.informatik.uni-frankfurt.de>

Show Full Headers
Complete Article Headers
Newsgroups: de.comp.lang.c++
Message-ID: <47lon8$ktb@news00.btx.dtag.de>
From: Krause@btx.dtag.de (Karl-Heinz Krause)
Path: arc1-ca.pugleaf.net!news00.btx.dtag.de!not-for-mail!Krause
Subject: Re: enums
Date: Mon, 06 Nov 1995 18:46:48 +0000
References: <47cqj5$d70@zeus.rbi.informatik.uni-frankfurt.de>
X-Gateway: ZCONNECT XX ius.gun.de [UNIX/Connect v0.73]
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit