Topic: enums comparisons
Author: "Radoslav Getov" <nospam@mai.com>
Date: Mon, 30 Jul 2001 16:54:12 CST Raw View
My compiler does not complain about this code:
enum A { a, b};
enum B { c, d};
if (a == b) <<< I expect diagnostics here
;
(Yes I know enums are convertible to int, but I thought it is 'at most one
only'
Isn't it right or wrong?
Radoslav Getov
---
[ 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 ]
Author: "James Russell Kuyper Jr." <kuyper@wizard.net>
Date: Mon, 30 Jul 2001 23:01:40 GMT Raw View
Radoslav Getov wrote:
>
> My compiler does not complain about this code:
>
> enum A { a, b};
> enum B { c, d};
> if (a == b) <<< I expect diagnostics here
> ;
>
> (Yes I know enums are convertible to int, but I thought it is 'at most one
> only'
Yes, there is a limit of one user-defined conversion per conversion
sequence, but there's a seperate conversion sequence for each argument
to operator==().
In any event, you're comparing two values of the same type, so no
conversion is needed.
> Isn't it right or wrong?
Yes, of course. The important thing, of course, is know which of the two
it is.
---
[ 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 ]