Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!apollo!mrst!sdti!wmm From: wmm@sdti.com (0006-William M. Miller(0000)) Newsgroups: comp.lang.c++ Subject: Re: Help! Keywords: constructors, C++ i/o, extern Message-ID: <1989Jul7.100843.1783@sdti.com> Date: 7 Jul 89 10:08:00 GMT References: <2774@ssc-vax.UUCP> Reply-To: wmm@sdti.UUCP (0006-William M. Miller) Organization: Software Development Technologies, Sudbury MA Lines: 20 In article <2774@ssc-vax.UUCP> dmg@ssc-vax.UUCP (David Geary) writes: >So now, I can use cout << ... but I cannot have the object myjunk >external, it has to be in main(). > > Can anybody provide an explanation as to why this is happening? Yes, you've been bitten by the "undefined static constructor order" bug. "cout" is a static object of class "ostream" which is defined in the library code somewhere. "myjunk" (in the nonworking example) is a static object of class "junk" which is defined in your program. When static objects are defined in different files, the order in which their constructors are invoked is not defined (within a file, it's done in declaration order). In your case, "myjunk" is being constructed before "cout," so saying "cout <<" in the constructor uses an uninitialized object. -- Non-disclaimer: My boss and I always see eye-to-eye (every time I look in the mirror). ...!genrad!mrst!sdti!wmm