Path: utzoo!attcan!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Scoping Bug Message-ID: <36159@brunix.UUCP> Date: 12 Apr 90 16:09:55 GMT Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 75 In article <1251@crabcake> zhu@crabcake.cs.jhu.edu (Benjamin Zhu) writes: >In article <2582@ektools.UUCP> randolph@ektools.UUCP (Gary L. Randolph) writes: >[stuffs deleted here] >>There appears to be a scoping problem with locally defined classes >>that contain a member function. The following example compiles without >>a hitch on my Sun. I am using Sun's 2.0 cfront. >> >>#include >>main() >>{ >>void func(); //prototype >> >>//local class definition >>class X{ >> public: >> int i; >> float f; >> void printIt(){cout<<"\nHello\n";} >>}c; >>c.i = 1; >>c.f = 3.3; >>c.printIt(); >>cout<<"\ni: "<>func(); >>} >> >>void func(){ >>X x; //COMPILER TAKES THIS >>x.i = 2; >>x.f = 44.5; >>cout<<"\ni: "<>} > >Our AT&T cfront 2.0 also displays the same problem. Personally I believe >it is a scoping bug. Actually there is a paragraph concerning this in >Lippman's C++ Primer (pp222-223). This is not a bug, it is the way C++ is defined to behave. Basically, there is no such thing as a "locally defined class" in C++. Classes defined inside classes and classes defined inside functions are all in the global name space. Scott S i g h S i g h S i g h S i g h S i g h S i g h