Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!XEROX.COM!SJohnson.ElSegundo From: SJohnson.ElSegundo@XEROX.COM Newsgroups: comp.lang.c++ Subject: Are Class Decl.'s Legal in Funcs ? Message-ID: <890403-150348-4532@Xerox> Date: 3 Apr 89 22:03:57 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: SJohnson.ElSegundo@Xerox.COM Organization: Xerox, El Segundo, Ca. Lines: 32 Is the following code legal ? Since C/C++ doesn't allow lexical nesting of functions, I'd be inclined to believe that having My_Class::doit() inside func would be a no-no. As it turns out, Oregon Software's occ will compile and run the example below, while Gnu's g++ (version 1.32.0) goes into some kind of infinite loop during compilation. Swen Johnson SJohnson.ElSegundo@Xerox.COM ------------------------------------------------------------------------- #include void func() { class My_Class { int var; public: void doit() { var = 1; cout << "var = " << var << "\n"; }; }; My_Class my_object; my_object.doit(); }; main () { func(); }; -------------------------------------------------------------------------