Article View: comp.std.c++
Article #1322Inheritance for enum types ???
From: Ron Guilmette
Date: Sat, 25 May 1991 07:43
Date: Sat, 25 May 1991 07:43
40 lines
1619 bytes
1619 bytes
Somebody over in comp.lang.c++ asked an interesting question about the
case where you have two or more enum types declared in the same scope
and where each enum type contains a declaration of a particular enumerator
name, like:
enum fruit { apple, orange, banana };
enum color { red, orange, yellow };
You can't do this because you will get an error on the (re)declaration of
`orange'.
Sometimes though, it would be nice to be able to do something like this,
e.g. when you want to have one type which refers to a whole big range
of enumerator values, and yet another type which represents some "subrange"
of the larger range of enumerator values.
So I was thinking... this sounds like a job for ... ta da! Inheritance!
Sure. Why not?
enum light_color { pink, yellow, aqua };
enum color : light_color { red, green, blue };
enum light_color LC;
enum color C;
LC = pink; // ok
C = pink; // also ok
LC = red; // buzzzzzt... wrong... but thanks for playing
Does anybody (other than me) think that this might be a good idea?
After all, in C++ we *do* now have strict type checking for enum types,
however we *don't* have anything like Pascal subranges.
Technical Details
Message-ID:
<5701@lupine.NCD.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!udel!rochester!kodak!uupsi!lupine!lupine.ncd.comShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!udel!rochester!kodak!uupsi!lupine!lupine.ncd.com From: rfg@lupine.ncd.com (Ron Guilmette) Newsgroups: comp.std.c++ Subject: Inheritance for enum types ??? Message-ID: <5701@lupine.NCD.COM> Date: 25 May 91 07:43:08 GMT Sender: rfg@NCD.COM Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 40