From 3542076930383489998 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,e422f6e841d07a08 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 1995-03-28 07:24:04 PST Newsgroups: comp.std.c++ Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!utnut!utcsri!cdf.toronto.edu!g2devi From: g2devi@cdf.toronto.edu (Robert N. Deviasse) Subject: Re: "Subclassing" Enums Message-ID: Sender: news@cdf.toronto.edu (Usenet News) Nntp-Posting-Host: hermia Organization: University of Toronto, Computing Disciplines Facility References: <3l72bh$8tf@crchh299.bnr.ca> Date: Mon, 27 Mar 1995 20:00:04 GMT Lines: 87 In article <3l72bh$8tf@crchh299.bnr.ca>, Joel Schmidt wrote: > >I recently found myself in a situation where I had declared an >enumeration in a base class, and then wished to "subclass" that >enumeration in a derived class, i.e: > >clase base { > enum baseEnum { > // some values related to functionality of base class > } >} > >class derived : base { > enum derivedEnum { > // all values in base enum > // plus some more associated with augmented functionality of derived class. > } >} > >The only way I could see to do this was to declare entirely new symbols >in the derived enumeration and equate them to those in the base enumeration. >This is of course both tedious and poses a maintenance nightmare. > >Given the nature of class hierarchies, I think it would be quite beneficial >if you could say: > > enum derivedEnum : baseEnum { > // just the new symbols > } > Actually, baseEnum is not a subclass of derivedEnum, it's an extension. Here's an example of the difference. enum Decimal { Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine }; enum Hexadecimal : Decimal { A, B, C, D, E, F }; void fd(Decimal&); void fh(Hexadecimal&); Decimal d=A; // illegal Hexadecimal h=Zero; // legal fd(h); // legal fh(d); // illegal Compare this with: struct Dec { Dec() {} }; struct Hex : Dec { Hex() {} }; void fd(Dec&); void fh(Hex&); Dec d=Hex(); // legal Hex h=Dec(); // illegal fd(h); // legal fh(d); // illegal Given this difference, the subclass syntax is quite misleading. The issue has been discussed here and in other forums before (eg in the Ada standardization effort). I can't remember the reasons (can anyone else remember?), but unfortunately it was discovered that this feature is problematic. Pity, I agree that it`s a feature that I`ve longed for once every blue moon. Someone posted a way to fake a version of this feature in C++ with templates some time ago. I'll see if I still have a copy of it and mail it to you. >-- >[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~] >[~ Joel A. Schmidt The reasonable man adapts himself ~] >[~ BNR, CSN Development. to the world; the unreasonable one persists ~] >[~ I speak for myself. in adapting the world to himself. Therefore, ~] >[~ chaos@bnr.ca all progress depends upon the unreasonable man. ~] >[~ (214) 684-4251 --George Bernard Shaw ~] >[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~] > Take care Robert -- /----------------------------------+------------------------------------------\ | Robert N. Deviasse |"If we have to re-invent the wheel, | | EMAIL: g2devi@cdf.utoronto.ca | can we at least make it round this time"| +----------------------------------+------------------------------------------/