Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!polyslo!ttwang From: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Newsgroups: comp.lang.c++ Subject: order which the constructors are called Message-ID: <1989Oct18.202605.5971@polyslo.CalPoly.EDU> Date: 18 Oct 89 20:26:05 GMT Reply-To: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Distribution: usa Organization: Cal Poly State University -- San Luis Obispo Lines: 38 I have a class with a data member that need to be initialized before all other data members in that class. As I seem to recall that the order of constructing data members is undefined, I wonder if it's still the case? class student { public: student(); // 'header' need to be initialized before 'the_foo' header_student header; bar the_bar; foo the_foo; }; student::student() : header(this), the_foo() {} I thought of initializing 'header' in the overloaded 'new' operator, but that will not work either. In the case of a stack object, the 'new' operator will not be called. If there is no official order of calling the constructors, is there any 'defacto' order of calling the constructors? Intuitively speaking, I think the order of construction should be 'header', 'the_foo', followed by the unmentioned data member 'the_bar'. In this case, 'header' contains garbage collection information, so it need to be initialized before the constructors of other data members allocate any additional storage space. -Thomas Wang ("This is a fantastic comedy that Ataru and his wife Lum, an invader from space, cause excitement involving their neighbors." - from a badly translated Urusei Yatsura poster) ttwang@polyslo.calpoly.edu