🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2248

Re: Inheriting Enums

#2248
From: Steve Clamage
Date: Thu, 19 Oct 1995 04:02
44 lines
2156 bytes
In article MAA13614@atlanta.com, wslade@atlanta.com writes:
>I have been using enums to define error numbers within a specific class.
>I now want to derive a class from this base. I would also like to derive
>the enum from the base.
> 
> ...
>
>Has anyone ever wanted to do this or is there another way of doing
>the same thing.
>Is this a possibility of being added to the C++ standard.

Things like this have been discussed informally, such as being able to
derive from non-class types in general. For example, it would be nice
to be able to write
	class MyInteger : public int { ... };

Such capability will not be added to the language in this round. Maybe
C++ 2005 :-)

In the mean time, you can get the the effect you want because additional
constants of the enum type may be defined as long as they fall within the
range of the original enum (extended to a power of 2 less one).
For example:

	class chili {
	public:
		enum hotness { low=0, medium=500, high=1000, scary=10000 };
	};

Now you can define constants of type chile::hotness with any value
in the range 0 through 32767, the extended range of hotness.

	class jalapeno : public chili {
	public:
		static const hotness hot_jal = medium+300;
		static const hotness med_jal = medium;
		static const hotness mild_jal = medium-200;
	};
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <463i2e$p22@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <199510181645.MAA13614@atlanta.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 19 Oct 95 04:02:11 GMT
Approved: fjh@cs.mu.oz.au
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Inheriting Enums
X-Original-Date: 18 Oct 1995 18:46:38 GMT
Organization: Sun Microsystems Inc.
Message-ID: <463i2e$p22@engnews2.Eng.Sun.COM>
References: <199510181645.MAA13614@atlanta.com>
Reply-To: clamage@Eng.Sun.COM
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMIXOAOEDnX0m9pzZAQGe4AF9GTKjrlkPR8nW83QTOkNc8LXGVSSZGjJ5
 xefe9o3EbQHSTwmQ5Oa+XtHFiZ9xm+hH
 =AD4s