Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!kodak!ektools!randolph From: randolph@ektools.UUCP (Gary L. Randolph) Newsgroups: comp.lang.c++ Subject: Re: order which the constructors are called Message-ID: <2194@ektools.UUCP> Date: 19 Oct 89 12:45:50 GMT References: <1989Oct18.202605.5971@polyslo.CalPoly.EDU> Sender: randolph@ektools (Gary L. Randolph) Reply-To: randolph@ektools.UUCP (Gary L. Randolph) Distribution: usa Organization: Eastman Kodak, Dept. 47, Rochester NY Lines: 34 In article <1989Oct18.202605.5971@polyslo.CalPoly.EDU> ttwang@polyslo.CalPoly.EDU (Thomas Wang) writes: #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? The order has always been defined, but it is defined differently than it was originally. You can count on data members being constructed: IN THE ORDER OF DECLARATION WITHIN THE CONTAINING CLASS. (Never trust me:-)) This is written on page 242 in Lippman. BTW, in the old days (??) the construction order followed the order of the member initialization list of the containing class. That's the list after the colon in the containing class constructor. # #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() The order used to follow ^^^^^^^^^^^^^^^^^^^^^^^^. BUT NOW THE ORDER FOLLOWS THE ORDER OF DECLARATION. #{} Gary Randolph Eastman Kodak