Article View: comp.std.c++
Article #2242Re: Inheriting Enums
From: Christopher Sweeney
Date: Wed, 18 Oct 1995 19:58
Date: Wed, 18 Oct 1995 19:58
51 lines
2216 bytes
2216 bytes
wslade@atlanta.com wrote:
>I have been using enums to define error numbers within a specific class.
>I now want to derive a class from this base. I would also like to derive
>the enum from the base.
>
>For example
>
>class A
>{
> enum AError
> {
> eErrorOpen, eErrorClose
> }
>};
>
>class B : public A
>{
> enum BError : AError
> {
> eErrorPipeOpen // Would start at one more than AError::eErrorClose
> }
>};
>
>Has anyone ever wanted to do this or is there another way of doing
>the same thing.
It is fairly easy to manage the enums by convention, e.g.
enum AError
{
eErrorOpen, eErrorClose, AErrorLast
}
enum BError
{
BErrorFirst = AErrorLast, eErrorPipeOpen // Would start at one more than
AError::eErrorClose
}
However, you cannot declare a member function that returns an AError OR a
BError (which is
probably what you are trying to do). The closest thing I've done invloves
introducing a baseclass
and then deriving from it. This may be quite a bit of overhead compared to
returning an int, but
it does have the advantage of a reasonably easy transition to exception
handling.
C. Sweeney
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<DGns2H.J3H@peacock.tcinc.com>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<199510181645.MAA13614@atlanta.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: Christopher Sweeney <csweeney@tcinc.com> Newsgroups: comp.std.c++ Subject: Re: Inheriting Enums Date: 18 Oct 1995 19:58:08 GMT Organization: Tele-Communications, Inc. Sender: news@tcinc.com (TCI External Internet News Administration) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <DGns2H.J3H@peacock.tcinc.com> References: <199510181645.MAA13614@atlanta.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; conversions="7bit, 7bit" Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: aitsun24 X-Mailer: Mozilla 1.1 (X11; U; SunOS 5.4 sun4m) X-Url: news:199510181645.MAA13614@atlanta.com Apparently-To: comp-std-c++@uunet.uu.net X-Lines: 47 Content-Length: 1122 Originator: clamage@taumet