Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!ben!richard From: richard@ben.Jpl.Nasa.Gov (Conan the Barbarian) Newsgroups: comp.lang.c++ Subject: initializing nested classes Keywords: classes Message-ID: <1990Mar9.235315.12054@elroy.jpl.nasa.gov> Date: 9 Mar 90 23:53:15 GMT Sender: news@elroy.jpl.nasa.gov (Usenet) Distribution: usa Organization: Image Analysis Systems Grp, JPL Lines: 29 Is there a way to initialize a nested class using a value (variable) in the constructor for the nesting class? For example I have a class which creates a window, the window contains a panel and several buttons. The window constructor creates a window which is used to create a panel which is then used in the calls to create the buttons. However, if I create the buttons as classes which are members of the window class, the constructor for the buttons is called before the constructor for the window is entered. Bass-ackwards so to speak. I get an error message indicating the panel variable is not defined in the button initializer reference. base_frame::base_frame(char *stuff):button(panel,more_stuff) { Panel panel; . . . } This may be a question of improper construction of the classes. Or there may be a way of delaying the member construction (sounds unlikely to me). Any suggestions would be appreciated. The example does not seem like a radical approach for an "object oriented" language. I have rtfm'd with no luck. The references (Stroustrup, AT&T, Sun) don't seem to talk about non-trivial constructors for nested classes. Possibly the answer is trivial but I just don't see it.