Thread View: net.lang.c++
1 messages
1 total messages
Started by Stephen J. Muir
Tue, 12 Aug 1986 20:02
Constructor execution ordering between modules.
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads