Article View: comp.std.c++
Article #1325Re: Inheritance for enum types ???
From: David S. Masterson
Date: Mon, 27 May 1991 05:39
Date: Mon, 27 May 1991 05:39
34 lines
2037 bytes
2037 bytes
>>>>> On 25 May 91 07:43:08 GMT, rfg@lupine.ncd.com (Ron Guilmette) said:
Ron> enum fruit { apple, orange, banana };
Ron> enum color { red, orange, yellow };
Ron> You can't do this because you will get an error on the (re)declaration of
Ron> `orange'.
Ron> Sometimes though, it would be nice to be able to do something like this,
Ron> e.g. when you want to have one type which refers to a whole big range of
Ron> enumerator values, and yet another type which represents some "subrange"
Ron> of the larger range of enumerator values.
Ron> So I was thinking... this sounds like a job for ... ta da! Inheritance!
Ron> enum light_color { pink, yellow, aqua };
Ron> enum color : light_color { red, green, blue };
This is a bit confusing as you would tend to think of Light_Color as a
derivative of Color, not vice versa. It would probably also be true that
people would start with a general definition (Color) and later specialize it
to their needs (Light_Color). Perhaps something like:
enum color { pink, yellow, aqua, red, green, blue };
enum light_color : color { pink, yellow, aqua };
BTW, how hard would this be to simulate using classes?
--
====================================================================
David Masterson Consilium, Inc.
(415) 691-6311 640 Clyde Ct.
uunet!cimshop!davidm Mtn. View, CA 94043
====================================================================
"If someone thinks they know what I said, then I didn't say it!"
Technical Details
Message-ID:
<CIMSHOP!DAVIDM.91May26223941@uunet.UU.NET>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!cimshop!davidmReferences:
<5701@lupine.NCD.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.std.c++ Subject: Re: Inheritance for enum types ??? Message-ID: <CIMSHOP!DAVIDM.91May26223941@uunet.UU.NET> Date: 27 May 91 05:39:41 GMT References: <5701@lupine.NCD.COM> Sender: davidm@cimshop.UUCP Distribution: comp Organization: Consilium Inc., Mountain View, California Lines: 34 In-reply-to: rfg@lupine.ncd.com's message of 25 May 91 07:43:08 GMT