Topic: operator overloading and enumeration types
Author: Luddy Harrison <luddy@concmp.com>
Date: 1998/02/24 Raw View
I have a question concerning the resolution of overloaded operators,
and enumeration types.
Section 13-24, paragraph 19 of CD2 says this:
For every triple (L, VQ, R), where L is an arithmetic or
enumeration type, VQ is either volatile or empty, and
R is a promted arithmetic type, there exist candidate operator
functions of the form
VQ L& operator=(VQ L&, R);
VQ L& operator*=(VQ L&, R);
VQ L& operator/=(VQ L&, R);
VQ L& operator+=(VQ L&, R);
VQ L& operator-=(VQ L&, R);
This seems to imply that I can write this:
enum color { red, blue };
void f() { color x = red; red += 1; }
I was under the impression that enumeration types could not be
operated upon in this way.
Now, the language of paragraphs 4-6 of the same section indicate
that there are no candidate functions of the form
T& operator++(T&);
T& operator--(T&);
where T is an enumeration type. This would seem to imply that I
cannot change my example above to
enum color { red, blue };
void f() { color x = red; red++; }
Can someone familiar with the draft standard shed some light on this?
Thanks in advance,
-Luddy Harrison (luddy@concmp.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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Luddy Harrison <luddy@concmp.com>
Date: 1998/02/25 Raw View
My examples have typos; they should read this way:
enum color { red, blue };
void f() { color x = red; x += 1; }
^
and
enum color { red, blue };
void f() { color x = red; x++; }
^
-Luddy Harrison (luddy@concmp.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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Luddy Harrison <luddy@concmp.com>
Date: 1998/02/27 Raw View
I'm afraid the typos in my original post have obscured the question I
intended to ask; let me try again.
Is this legal?
enum color { red, blue };
void f() { color x = red; x += 1; }
How about this?
enum color { red, blue };
void f() { color x = red; x++; }
Section 13-24, paragraph 19 of CD2 seems to permit the former.
Section 13-24, paragraph 6 seems to forbid the latter.
I suspect that both are intended to be illegal, but I can't
believe that the latter would be forbidden if the former is legal.
-Luddy Harrison (luddy@concmp.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://reality.sgi.com/austern_mti/std-c++/faq.html ]