🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1808

Re: constructor problem with g++1.34 on sun4-os4

#1808
From: Clark Cooper
Date: Fri, 31 Mar 1989 14:29
33 lines
1553 bytes
In <8903301644.AA01395@toadwar.UCAR.EDU> gerry wiener writes:
}I believe the following program should print
}
}Initialize
}Hello, world
}Clean up
}
}Instead it prints
}
}Hello, world
}Clean up
}
}If the definition of y is placed inside main(), then the program prints
}
}Initialize
}Hello, world
}Clean up

	[followed by a program that has a class constructor
	 that uses cout and then declares a global instance
	 of the class]

	The gotcha here is that 'cout' is also a class object and has to
be initialized. Since you don't have any guarantee about order of
initialization of global objects, it is possible that object-y's
constructor is called before cout's is. If you had used 'printf' instead
of streams, you would have seen that y's constructor was in fact called.
--
======================================================
Clark Cooper		cooper@gecrux.steinmetz.ge.com
(518) 387-5887		coopercc@crd.ge.com
			...!uunet!steinmetz!cooper
Technical Details
Message-ID: <COOPER.89Mar31092909@gecrux.steinmetz.ge.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pacbell!lll-winken!uunet!crdgw1!steinmetz!kbsvax!cooper
References: <8903301644.AA01395@toadwar.UCAR.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pacbell!lll-winken!uunet!crdgw1!steinmetz!kbsvax!cooper
From: cooper@gecrux.steinmetz.ge.com (Clark Cooper)
Newsgroups: gnu.g++.bug
Subject: Re: constructor problem with g++1.34 on sun4-os4
Message-ID: <COOPER.89Mar31092909@gecrux.steinmetz.ge.com>
Date: 31 Mar 89 14:29:09 GMT
References: <8903301644.AA01395@toadwar.UCAR.EDU>
Sender: news@steinmetz.ge.com
Distribution: gnu
Organization: GE Corporate Research & Development
Lines: 33
In-reply-to: gerry@TOADWAR.UCAR.EDU's message of 30 Mar 89 16:44:31 GMT