Topic: enum++??
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Wed, 16 Mar 1994 02:09:00 GMT Raw View
In article <vini-120956163539@149.98.130.102> vini@khis.com (vinayak lawande) writes:
>>
>Can you overload operator ++ (or any other ) for enum object ?. I was
>under impression that you can overload operator only for class objects. Is
>this a new feauture ...
Yes.
>I tried to overload ++ operator for enum on Sun 3.0.1 and it does not allow
>it.
>Do you think it is a bug....
No. Its just not up to date.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: vini@khis.com (vinayak lawande)
Date: Thu, 3 Mar 1994 22:33:29 GMT Raw View
In article <1994Feb27.160919.23168@sco.COM>, simon@sco.COM (Simon Tooke)
wrote:
> In <2kj9c9$ejg@news.icaen.uiowa.edu> nvkumar@l-ecn007.icaen.uiowa.edu (Neel Vasant Kumar) writes:
>
> >Simon Tooke (simon@sco.COM) wrote:
> >: In <2k79j9$qp8@aludra.usc.edu> eddykim@aludra.usc.edu (Eddy Kim) writes:
>
> >: > I'm using g++ to write some code in which I have an array of strings
> >: >indexed by enum values. Then I use the enum in a loop to iterate through
> >: >the string table. The compiler warns that it's illegal in ANSI C++.
> >: > "warning: ANSI C++ forbids incrementing an enum"
> >: >Is it true? I just looked through the ARM in the enum section (sec 7.2), and
> >: >didn't see a mention of this restriction. If it is true, would anyone like
> >: >to give me a reason why?
>
> >: Because incrementing an enum used to mean essentially to add 1 to it's
> >: underlying value, which may cause the enum to have an illegal value.
> >: (as in "enum foo { one=1, four=4 } bar = one; bar++;". Bar used to come
> >: out `2', which is not a valid value for a foo. Nowdays you can define
> >: an overloaded operator ++ for foo which actually really cycles through enum
> >: values, but you have to create this function manually.
>
> >: -simon tooke
>
Can you overload operator ++ (or any other ) for enum object ?. I was
under impression that you can overload operator only for class objects. Is
this a new feauture ...
I tried to overload ++ operator for enum on Sun 3.0.1 and it does not allow
it.
Do you think it is a bug....
vini...
Author: simon@sco.COM (Simon Tooke)
Date: Sun, 27 Feb 1994 16:09:19 GMT Raw View
In <2kj9c9$ejg@news.icaen.uiowa.edu> nvkumar@l-ecn007.icaen.uiowa.edu (Neel Vasant Kumar) writes:
>Simon Tooke (simon@sco.COM) wrote:
>: In <2k79j9$qp8@aludra.usc.edu> eddykim@aludra.usc.edu (Eddy Kim) writes:
>: > I'm using g++ to write some code in which I have an array of strings
>: >indexed by enum values. Then I use the enum in a loop to iterate through
>: >the string table. The compiler warns that it's illegal in ANSI C++.
>: > "warning: ANSI C++ forbids incrementing an enum"
>: >Is it true? I just looked through the ARM in the enum section (sec 7.2), and
>: >didn't see a mention of this restriction. If it is true, would anyone like
>: >to give me a reason why?
>: Because incrementing an enum used to mean essentially to add 1 to it's
>: underlying value, which may cause the enum to have an illegal value.
>: (as in "enum foo { one=1, four=4 } bar = one; bar++;". Bar used to come
>: out `2', which is not a valid value for a foo. Nowdays you can define
>: an overloaded operator ++ for foo which actually really cycles through enum
>: values, but you have to create this function manually.
>: -simon tooke
>Would it be useful to expect the compiler to come up with a defualt
>incrementor?? I personally think that it would....
>Neel Vasant Kumar | #include <disclaimer,h>
>nvkumar@icaen.uiowa.edu | Don't discriminate, lest you be discriminated....
The compiler has no knowledge of the purpose of your enum. It may end up
producing an incrementor for a bitfield, or for totally different unrelated
values (to clarify: in class definitions, sometimes class constants are grouped
in enums just so they are available at compile time, instead of in static
integral-typed members). One of the guiding principles has been (and I'm not
saying this has always or will always hold) that you don't pay for what you
don't use. In this case, a (potentially) useless compiler-generated function.
In addition, if the compiler did this, illegal incrementing of enums that
were never meant to be incremented could not be caught.
-simon tooke
Author: eddykim@aludra.usc.edu (Eddy Kim)
Date: 20 Feb 1994 01:13:13 -0800 Raw View
Hi,
I'm using g++ to write some code in which I have an array of strings
indexed by enum values. Then I use the enum in a loop to iterate through
the string table. The compiler warns that it's illegal in ANSI C++.
"warning: ANSI C++ forbids incrementing an enum"
Is it true? I just looked through the ARM in the enum section (sec 7.2), and
didn't see a mention of this restriction. If it is true, would anyone like
to give me a reason why?
Thanks
--
--
Ed
eddykim@usc.edu
Author: simon@sco.COM (Simon Tooke)
Date: Sun, 20 Feb 1994 22:25:48 GMT Raw View
In <2k79j9$qp8@aludra.usc.edu> eddykim@aludra.usc.edu (Eddy Kim) writes:
>Hi,
> I'm using g++ to write some code in which I have an array of strings
>indexed by enum values. Then I use the enum in a loop to iterate through
>the string table. The compiler warns that it's illegal in ANSI C++.
> "warning: ANSI C++ forbids incrementing an enum"
>Is it true? I just looked through the ARM in the enum section (sec 7.2), and
>didn't see a mention of this restriction. If it is true, would anyone like
>to give me a reason why?
Because incrementing an enum used to mean essentially to add 1 to it's
underlying value, which may cause the enum to have an illegal value.
(as in "enum foo { one=1, four=4 } bar = one; bar++;". Bar used to come
out `2', which is not a valid value for a foo. Nowdays you can define
an overloaded operator ++ for foo which actually really cycles through enum
values, but you have to create this function manually.
-simon tooke
===============================================================================
Simon Tooke (not speaking for) SCO Canada, Inc. Voice: (416) 922-1937
....!scocan!simon simon@sco.com Fax: (416) 922-2704
130 Bloor St. West. Suite 1001, Toronto, Ontario, Canada M5S 1N5