williamt@athena1.Sun.COM (William A. Turnbow) (04/12/90)
I have the following code which works fine under 'c', but not when
compiled by c++.
------
enum temps {hot, medium, cold};
enum heights {high, medium, low };
main()
{
enum temps t;
enum heights h;
t=medium;
h=medium;
}
-----------
C++ complains about having enumerator medium declared twice. It also
complains down in line 11 (h=medium), that I am trying to assign
something of type 'const enum temps' to something of enum heights.
Now from the second error message, it is seen that c++ has assigned
a type to 'medium' that makes it incompatible with something of type
'heights'. From this, it follows that medium declared as part
of one enum, is different than medium declared of another. Thus,
it would seem that the first error message is not valid.
Now one could argue that it would be difficult to determine the type of
of 'medium' naked in an RHS, but similar rules that govern float->int
conversion could apply. If we have something of enumerated type
on the LHS of an equal, or a comparison, let's say, then if it has
a member of type 'medium', that medium would be used.
If it doesn't have a 'medium' member, then medium from any enum can
be used if all values for medium are the same (as in my example above).
If there are differing values for medium, an error of being unable to
convert to due ambiguous conversions should be issued.
Anyway, as it stands now, it is a logical bug. The compiler claims
'medium' is duplicate in the first error (no typing), but then claims
it is different (with typing) in the second.
Is this a flaw in the language, or just the implementation I'm
using?
-wat-
--- An it harm none, do what you will.
*** America vs. developed country rankings: chemistry 11/13, physics 9/13
biology 13/13, infant mortality 1/13, teen pregnancy 1/13