Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond!diamond From: diamond@diamond.csl.sony.junet (Norman Diamond) Newsgroups: comp.lang.c++ Subject: Re: Enumerated types in C++ Message-ID: <10174@socslgw.csl.sony.JUNET> Date: 17 Apr 89 03:25:18 GMT References: <874@sl10c.concurrent.co.uk> <176@riunite.ACA.MCC.COM> Sender: news@csl.sony.JUNET Reply-To: diamond@diamond.csl.sony.jp (Norman Diamond) Organization: Sony Computer Science Laboratory Lines: 37 In article <176@riunite.ACA.MCC.COM> rfg@riunite.UUCP (Ron Guilmette) writes: i >Now consider the following which G++ *does* allow: n > e >enum color { red, green, blue }; w >enum fruit { apple, banana }; s > >overload function; s >void function (color c) { } u >void function (fruit f) { } c >void function (int i) { } k > s >int test () >{ - > function (apple); - > function (red); - > function (99); - >} - > - >Is g++ handling the above source code incorrectly, or does a "standard conforming" - >C++ compiler/translator have to remember the precise (enum) type associated with - >any given enum constant name? This does seem to be an error in g++. Since C++ usually tries to be compatible with C (and Pantsy C), apple and red must be constants of some integral type, and color and fruit must be some integral type. If color and fruit are int itself, then the three declarations of f cannot be disambiguated, and all three calls are ambiguous. If color and fruit are (say) short and/or unsigned, then the first two declarations of f still cannot be disambiguated, and all three calls are still ambiguous. If function is not overloaded but only declared to take an argument of color, then all three calls must call it. Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-inventing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?