Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!cerc.utexas.edu!lynch From: lynch@cerc.utexas.edu (Tom Lynch) Newsgroups: comp.lang.c++ Subject: Re: inline member functions returning a enumerated type Summary: example didn't work Message-ID: <1990Jul27.234044.8701@cerc.utexas.edu> Date: 27 Jul 90 23:40:44 GMT References: <1851@island.uu.net> <1990Jul27.083837.2078@cerc.utexas.edu> <10589@batcomputer.tn.cornell.edu> Sender: root@cerc.utexas.edu (Operator) Distribution: na Organization: University of Texas at Austin Lines: 59 In article <10589@batcomputer.tn.cornell.edu> lijewski@tcgould.tn.cornell.edu (Mike Lijewski) writes: >In article <1990Jul27.083837.2078@cerc.utexas.edu> lynch@cerc.utexas.edu (Tom Lynch) writes: > >>In this case 'id' is already an enum type, so adding the 'enum' in >>front of it is erroneous. Also, one should not place the extra 'struct' in >>front of structure types. > >Adding an "extra" enum (or any typename for that matter) is not erroneous. >In fact, there are cases in C++ programming (see appended example) where >you are be forced to write 'enum id' instead of just 'id'. > >>p309 of The C++ Programming Language by Bjarne Strouistup, r14, >>Differences from C: >> "The name of a class or enumeration is a type name" > >Very true. But unlike C, typenames and non-type names are in the same >name space C++. So sometimes you must use the typename explicitely to >differentiate between a typename and non-type name. > ... > >/****** EXAMPLE ******/ > >enum S { A, B, C }; > >int >main() >{ > int S; > S s; // this is an error; must be 'enum S s;' > > return 0; >} > > mike, I tried your example: enum S {A,B,C}; int main() { int S enum S s; return 0; } and got: test.C: In function int main (): test.C:6: parse error before `enum' got the same error the original poster did. Hmmm, Could you provide a reference to kind of typing you are demonstrating - I looked in Lippman and of course Stroupstrup and couldn't find it. Please use E&S. tom lynch@cerc.utexas.edu Nothing is absolute.