I'm using Microsoft Visual C++ 2010 Express, and it require I use: system("pause"); before entering the return 0 or exit, statements. The author seems to use a different software/compiler which doesn't require system("pause").
This system("pause") [sp statement], seems to be the culprit in why the following program won't display all of the output, which is supposed to be:
We will now define a DerivedClass object.
This is the BaseClass constructor.
This is the DerivedClass constructor.
The program is now going to end.
This is the DerivedClass destructor.
This is the BaseClass destructor.
Due to the sp statement, the last 2 lines of are not displayed. Removing it, will get the last 2 lines to be displayed but the program will shutdown immediately after displaying the output.
I'd also like to use this post, to post problems related to programs example in the chapter of the text book.
Source code
// This program demonst rates the order in which bas and
// derived class constructors and destructors are called.
#include <iostream>
using namespace std;
//*******************************************
// BaseClass declaration
//*******************************************
class BaseClass
{
public:
BaseClass() // Constructor
{ cout << "This is the BaseClass constructor.\n"; }
~BaseClass() // Destructor
{ cout<< "This is the BaseClass destructor.\n"; }
};
//*************************************
// DerivedClass declaration
//*************************************
class DerivedClass : public BaseClass
{
public:
DerivedClass() // constructor
{ cout << "This is the DerivedClass constructor.\n"; }
~DerivedClass() // Destructor
{ cout<< "This is the DerivedClass destructor.\n"; }
};
//*************************************
// main function
//*************************************
int main()
{
cout << "We will now define a DerivedClass object.\n";
DerivedClass object;
cout << "The program is now going to end.\n";
system("pause");
return 0;
}
This post has been edited by mgrex: 25 February 2012 - 06:41 PM

New Topic/Question
Reply



MultiQuote





|