Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!brutus.cs.uiuc.edu!zaphod.mps.ohio-state.edu!mips!apple!hercules!sparkyfs!unix!hplabs!hp-ses!hpcuhb!hpcllla!hpclisp!hpcll05!pfaust From: pfaust@hpcll05.HP.COM (Paul Faust) Newsgroups: comp.lang.c++ Subject: Local classes, are they worth it???? Message-ID: <58170004@hpcll05.HP.COM> Date: 21 Feb 90 01:26:56 GMT Organization: Hewlett-Packard Calif. Language Lab Lines: 53 Local classes with the combination of the +d option give the illusion of Pascal style nested functions. In cfront, if a local class defines member functions (with their bodies), the +d option will cause the function to dumped out prior to the definition of the function currently being processed. Static members are properly hoisted out. However, locals that are defined prior to the class are not accessible and cfront generates an error. For example, in the following program: 1 int x_file; 2 3 class foo_file { 4 private: 5 int y_file; 6 public: 7 foo_file() {} 8 void do_it_file () { x_file = 1;} 9 }; 10 11 main () { 12 int x_local = 0; 13 14 class foo_local { 15 int y_local; 16 public: 17 foo_local() {} 18 void do_it_local () { x_local = 1; x_file = 2;} 19 }; 20 21 foo_file foo_int_file; 22 foo_int_file.do_it_file(); 23 24 foo_local foo_int_local; 25 foo_int_local.do_it_local(); 26 } On line 18, cfront reports an error message that x_local is undefined. I fail to see the difference between that and the access in the file scoped class accessing the file scoped variable. To implement this, there are two options: 1. All the locals are pulled out as well and appropriately mangled. 2. In a compiler solution, a static link ala Pascal is used for the member functions. Is the feature worth it, and as a side issue, are member function bodies defined within a class body, the real culprit of this problem, worth the complexity. The user already has an option to specify inline on any function. The body definition doesn't really buy you anything and will get you into the previously mention difficulty. What do people think???