Path: utzoo!attcan!uunet!decwrl!sdd.hp.com!usc!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: enum is a type Message-ID: <1990Jul27.083837.2078@cerc.utexas.edu> Date: 27 Jul 90 08:38:37 GMT References: <1851@island.uu.net> Sender: lynch@cerc.utexas.edu Distribution: na Organization: University of Texas at Austin Lines: 45 In article (Glenn Parker) writes: >In article <1851@island.uu.net> chris@island.uu.net (Chris King) writes: >> I could use some help figuring out a problem I am having with >> defining a inline member function that returns a enum. I don't >> ... >> struct test { >> enum id { A, B, C }; >> >> enum id v; >> >> test() { v = A; } >> inline enum id GetV() { return v; } > ^^^^^^ >> }; >> ... >> "TestClass.cc", line 8: error: bad base type: inline enum id > >Apollo C++ 2.0 gives the same error, if that's any comfort. > >Removing the indicated "inline", which is superfluous (but certainly not >illegal), makes the error go away. The function will still be inlined, >because it is declared within the struct definition. Alternatively, >removing the "enum" following the indicated "inline" will _also_ make the >error go away. Again, the enum is superfluous (but not illegal, I think), >since "id" is sufficient to identify the type of the function. > >Looks like a compiler bug to me, but nothing too serious. 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. p309 of The C++ Programming Language by Bjarne Strouistup, r14, Differences from C: "The name of a class or enumeration is a type name" of the same book, Note to C Programmers "The better on knows C, the harder it seems to avoid writing C++ in C style ..." tom lynch@cerc.utexas.edu