Topic: Enum member functions (was C++0x)


Author: scotts@ims.com (Scott Schurr)
Date: Wed, 9 May 2001 17:35:38 GMT
Raw View
In article <OnHm12EhaF+6EwzR@ntlworld.com>, Francis Glassborow <francis.glassborow@ntlworld.com> writes:
|> In article <memo.20010508022024.35939F@brangdon.madasafish.com>, Dave
|> Harris <brangdon@cix.co.uk> writes
|> >Allow enum members to be qualified by the name of the enum they belong
|> >to. Eg:
|>
|> I think you are really asking that enums have a scope. Actually I would
|> like something more, I would like to see enums as full fledged types
|> with a scope in which member functions can be placed. Among other things
|> that would allow me to provide a specialised operator= for enums.
|>
|> Francis Glassborow      ACCU
|> 64 Southfield Rd
|> Oxford OX4 1PA          +44(0)1865 246490
|> All opinions are mine and do not represent those of any organisation

My favorite hope for enums is an enum forward declaration that
indicates the underlying type, so the storage requirements are
known by everything that sees the forward declaration.  That
would allow a class's header to declare storage for an enum
without knowing all the values that enum could take.

An example where is is useful is when class Alpha declares a public
enum, but another class (Beta) wants to carry an enum of that value.
Today, the header of class Beta must include the header of class
Alpha - which exposes Alpha to all users of Beta.  If Beta could
forward declare the enum (with sufficient size information), then
Beta's header could declare storage for the enum without including
Alpha's header.

I understand that this in some ways gives enums a preferential
place over classes, since a forward declared class may only be
operated on using a pointer or reference.  But enums started out
as simple beasts in C, and I guess I keep wishing to pull them
back in that direction.

Yes, I know there is a  work around today.  I could declare the
enum in it's own separate header wrapped in a namespace.  I
prefer to keep the enum in the class where it belongs, instead of
putting it in a separate file.  But that's just me, I guess.

Getting back to Francis's idea, adding operators to an enum would
also allow adding virtual operators and methods to the enum.  Now
the size of an enum is completely up for grabs since it may carry
a pointer to a virtual table.  And my wish for enum forward
declarations is toast.

I suppose that If I don't get my wish with regard to enum forward
declarations, then I lose nothing if Francis's suggestion is taken.

I'll watch the C++0x developments with interest.

--------------------------------------
Scott Schurr
  Integrated Measurement Systems, Inc.
  Voice: (503) 626-7117
  Fax:   (503) 644-6969
  Email: scotts@ims.com
--------------------------------------

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]