Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!claris!hearn From: hearn@claris.com (Bob Hearn) Newsgroups: comp.lang.c++ Subject: Re: Are Class Decl.'s Legal in Funcs ? Message-ID: <9501@claris.com> Date: 5 Apr 89 17:30:23 GMT References: <667@oresoft.uu.net> Organization: Claris Corporation, Mountain View CA Lines: 31 From article <667@oresoft.uu.net>, by dan@oresoft.uu.net (Daniel Elbaum): > In article <9418@claris.com> hearn@claris.com (Bob Hearn) writes: > :From article <890403-150348-4532@Xerox>, by SJohnson.ElSegundo@XEROX.COM: > :- Is the following code legal ? > :- > :- > : > :I don't know about classes nested in functions, but classes nested in > :classes are legal - except they don't mean what you think they do. Their > :scope is global. This is VERY ANNOYING. The one thing I hate most about > :C is lack of nested scoping. > > Declarations nested in class definitions are not global, but are limited > to the scope enclosing the class definition. Since class definitions are > normally performed outside of any block, nested declarations tend to take > on global scope. > > A declaration of a class in C++ is similar to a declaration of a struture > in C. The template may be declared and used in any block, and the scope > of the template definition is the block within which it is defined. The > same is true for any data type. C certainly has nested scoping. In a very limited sense. For C, the most important functionality of nested scoping is nested functions, which you can't have. In C++, you also want nested classes, which you can't have. These are major deficiencies. With C++, you can hack around the nested function problem by declaring a class within your function that has member functions which are effectively nested functions. But why should you have to? Bob Hearn hearn@claris.com