Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!orion.oac.uci.edu!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: Re: Typedef inside of a class definition. Message-ID: <26462BED.5865@paris.ics.uci.edu> Date: 8 May 90 02:16:13 GMT References: <3748@elysium.sw.mcc.com> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 40 In article <3748@elysium.sw.mcc.com> downing@elysium.sw.mcc.com (Glenn Downing) writes: > >Is it a bug in the GNU 1.37 compiler that it does not allow me to define a >typedef within a class definition and have its scope be global? The Sun >compiler does define it with global scope. > >class foo > {typedef bar int;}; > >main() > {bar i = 2;} // bar is not accessible here with GNU, but is with SUN >-- >Glenn Downing (downing@mcc.com) >Microelectronics Computer Corporation (MCC) >3500 West Balcones Center Drive >Austin, TX 78759-6509 I really should let Michael answer this one but... The C++ language rules have changed recently with respect to the scope of things declared within classes/structs/unions. It used to be that if you defined a type (via a typedef statement, or via a struct, class, union, or enum type definition) within a class, that the scope of the new typename was made "global". Nowadays, the scopes of such names are (or will soon be) restricted to the class itself (and its member functions of course). Cfront 2.0 doesn't implement this fully yet. I haven't seen what 2.1 does in such cases, so I don't know. g++ (1.37.1) went part of the way by making names defined via typedef statements local to the containing class. Whether that is a bug or a feature is (i think) in the eye of the beholder. // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.