Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsm!gregk From: gregk@cbnewsm.att.com (gregory.p.kochanski) Newsgroups: comp.std.c++ Subject: Re: Inheritance for enum types ??? Message-ID: <1991May30.003022.18328@cbnewsm.att.com> Date: 30 May 91 00:30:22 GMT References: <5701@lupine.NCD.COM> <1991May26.082057.6735@alias.com> Organization: AT&T Bell Laboratories Lines: 51 In article <1991May26.082057.6735@alias.com> rae@alias.com (Reid Ellis) writes: >Ron Guilmette writes: >|So I was thinking... this sounds like a job for ... ta da! Inheritance! >| enum light_color { pink, yellow, aqua }; >| enum color : light_color { red, green, blue }; > >A problem with this is that inheritance denotes an is-a relationship. >That is, an instance of a derived object is-a base object as well. >This would not be the case with the above since a 'color' can have a >value that has no meaning for a 'light_color'. Wrong. C++ and computer programming don't have 'is_a' relationships. They exist in the minds of the programmers. You are anthromorphizing the programming language by thinking of things this way. For instance 'is_a' does not apply at all if you have a private base class. The derived object cannot be used where a base object is asked for. You are also allowed to think of inheritance as reading 'and_more' (which would be appropriate to enumerations). For example, I can imagine the following situation. A computer is running some experiment, and we have a class which stores all the information that will control the experiment: class experimental_conditions { ... double voltage, other_experimental_parameters; ... }; Then, we can make a class which stores the measured data along with the conditions: class datum : public experimental_conditions { ... double whatever_was_measured; ... }; Now, whatever_was_measured is meaningless unless it is attached to the conditions that gave rise to it. For instance, 42 may be the answer, but it would be even more meaningful if the question were attached. So, now you can pass a datum to various routines which might display the conditions on menus, or whatever. I suppose you can think that 'a datum is an experimental condition', but you'd really have to stretch the English language and the meaning of the classes. A datum is *really* an experimental condition PLUS a measurement. This type of interpretation maps directly onto the suggested enhancement of enumerations.