Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI805.ASC

 
Output of file : TI805.ASC contained in archive : C-ALL.ZIP






PRODUCT : Turbo C++ NUMBER : 805
VERSION : All
OS : DOS
DATE : September 17, 1991 PAGE : 1/2

TITLE : Member Data Initialization -- Using a Constructor
Initialization List




The following code demonstrates the initialization of a class's
member data by using the initialization list of a class
constructor. It also shows how to call a base class constructor
from a derived class.

Since this code uses floating point, be sure to have floating
point emulations enabled (IDE) or include EMU.LIB and MATHx.LIB
at the appropriate location in the TLINK command line.

#include
#define HUND 100

class base {
public:
base() { cout << "in base\n"; }
};

class derive : public base {
int x, z;
float y;

public:
/* Note that the initialization list comes AFTER the
contructors formal arguments and a colon. Each
variable name is followed by an initial value in
parentheses. Each variable is separated from the
next by a comma. The value in the parentheses can
be either a variable from the constructor parameter
list, a value, an expression that results in a value,
or a constant.

At the end of the initialization list is the call to
the base class constructor. In this example, parameters
are not passed, however, parameters may be passed and
they may consist of a variable from the derived
constructor parameter list, a value, an expression
that results in a value, or a constant.

Note: a private or public member of the base class
cannot be initialized by the initialization list
of the derived constructor.
*/













PRODUCT : Turbo C++ NUMBER : 805
VERSION : All
OS : DOS
DATE : September 17, 1991 PAGE : 2/2

TITLE : Member Data Initialization -- Using a Constructor
Initialization List




// initialization list Call to base constructor
derive(int a) : x(a*a), z(HUND), y(4.33), base()
{
cout << "in derive\n";
}

void show(void)
{
cout << "x is " << x;
cout << "\nz is " << z;
cout << "\ny is " << y;
};

main()
{
derive dd(3);
dd.show();
}

































  3 Responses to “Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI805.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/