🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Expanding enumerators in inheriting classes

#112
From: Johan Bengtsson
Date: Thu, 13 Aug 1992 09:49
39 lines
2257 bytes
hildum@ntmtv.UUCP (Eric Hildum) writes:
: In article <1992Aug11.190816.8623@inmet.camb.inmet.com>, stt@spock.camb.inmet.com (Tucker Taft) writes:
: 
: |> 
: |> One reason we lost interest was the observation that record 
: |> extension/derivation tends to make enumeration types less necessary.  
: |> Rather than having a variant record/union type with a value of an enumeration
: |> type distinguishing the variants, one would simply define distinct
: |> derivations.  A virtual function could return a string name
: |> for each distinct derivation, corresponding to the enumeration literal.
: |> A separate virtual function could return an integer code, if needed.
: |> 
: 
: That is run time type information via string compares, or via integer compares.
: The problem with this is that now the programmer has to be concerned with the
: exact values returned from each different class to prevent conflicts within
: inheritance trees (and across such trees), [...]

A better approach is to have each class return a reference to a unique
object, one for each class, like this:

virtual const Type& someClass :: myType();
{
	static Type theType;	// unique type object
	return theType;
}

Since objects are guaranteed to have distinct addresses,
conflicts between class type identifiers are avoided.  Also,
the Type class can be extended with additional operations and
data.  You would probably want easy equality tests:

int operator == ( const Type& a, const Type& b )
{ return &a == &b; }
-- 
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| jbn@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490              |
--------------------------------------------------------------------------
Technical Details
Message-ID: <4818@holden.lulea.trab.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!bloom-beacon!eru.mt.luth.se!hagbard!loglule!jbn
References: <1992Aug12.192200.6873@ntmtv>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!bloom-beacon!eru.mt.luth.se!hagbard!loglule!jbn
From: jbn@lulea.trab.se (Johan Bengtsson)
Newsgroups: comp.std.c++
Subject: Re: Expanding enumerators in inheriting classes
Message-ID: <4818@holden.lulea.trab.se>
Date: 13 Aug 92 09:49:56 GMT
References: <1992Aug12.192200.6873@ntmtv>
Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
Lines: 39
X-Newsreader: Tin 1.1 PL4