Path: utzoo!utgpu!attcan!uunet!ncrlnk!fenix!tek From: tek@fenix.Atlanta.NCR.COM (Tom Klempay) Newsgroups: comp.lang.c++ Subject: Re: Global constructors and C++ I/O streams; problems and questions. Summary: Works with Zortech C++ (kind of) Message-ID: <386@fenix.Atlanta.NCR.COM> Date: 21 Oct 88 15:20:08 GMT References: <5955@columbia.edu> Organization: NCR Systems Engineering - Retail / Atlanta Lines: 40 In article <5955@columbia.edu>, beshers@select.columbia.edu (Clifford Beshers) writes: > The following program suffers a memory fault before it ever gets > to the first line of main(). The problem lies in the constructor > of the global instance 'example hello'; the reference to the > cout stream occurs before the initialization of that stream. > > > #include > class example { > public: > example() > { > cout << "Hello, world\n"; > } > }; > // Comment out this line and it works, of course. > example hello; > main() > { > cout << "We never get to the first line...\n"; > } Just to further muddy the waters, I just tried this with Zortech C++ (1.05), and the output is : c>foo We never get to the first line... c> It compiles fine (i.e. at least there were no errors or warnings :-), but, as shown above, it ignores the constructor output when "hello" is globally declared. Something strange going on here since it bombs on you but works (somewhat) for me. Tom Klempay - NCR SE-Retail | #ifndef _DISCLAIMER Atlanta, GA | #include tek@fenix.atlanta.ncr.com | #endif ...!ncrlnk!fenix!tek |