Article View: net.lang.c++
Article #281Constructor execution ordering between modules.
From: Stephen J. Muir
Date: Tue, 12 Aug 1986 20:02
Date: Tue, 12 Aug 1986 20:02
51 lines
1661 bytes
1661 bytes
Hi. This is my first posting to this newsgroup. I have been reading the book
by Bjarne Stroustrup, and decided to try problem 12 at the end of chapter 5.
For those of you without the book, here is the problem:
Given the program:
# include <stream.h>
main ()
{
cout << "Hello, world\n";
}
modify it to produce the output
Initialise
Hello, world
Clean up
Do not change main() in any way.
Easy, I thought:
# include <stream.h>
class x
{ char y;
public:
x() { cout << "Initialize\n"; }
~x() { cout << "Clean up\n"; }
};
x z;
main ()
{
cout << "Hello, world\n";
}
Unfortunately, all I get is:
Segmentation fault (core dumped)
When I remove the constructor, I correctly get the last two lines. It seems
that I was trying to use "cout" before it was initialised. Is this a bug, or
am I missing something?
--
EMAIL: stephen@comp.lancs.ac.uk | Post: University of Lancaster,
UUCP: ...!mcvax!ukc!dcl-cs!stephen | Department of Computing,
Phone: +44 524 65201 Ext. 4120 | Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution | LA1 4YR
Technical Details
Message-ID:
<349@comp.lancs.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephenShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephen From: stephen@comp.lancs.ac.uk (Stephen J. Muir) Newsgroups: net.lang.c++ Subject: Constructor execution ordering between modules. Message-ID: <349@comp.lancs.ac.uk> Date: Tue, 12-Aug-86 16:02:35 EDT Article-I.D.: comp.349 Posted: Tue Aug 12 16:02:35 1986 Date-Received: Wed, 13-Aug-86 06:21:58 EDT Reply-To: stephen@comp.lancs.ac.uk (Stephen J. Muir) Organization: Department of Computing at Lancaster University, UK. Lines: 51