Download C++: A Beginner`s Guide, Second Edition

Transcript
NOTE: Technically, there is a small difference between the two initialization forms, which you will learn about
later in this book. However, this difference does not affect the programs in this module, or most programs that you
will write.
Here is a complete program that demonstrates the MyClass parameterized constructor:
The output from this program is shown here:
5 19
Destructing object whose x value is 19
Destructing object whose x value is 5
In this version of the program, the MyClass( ) constructor defines one parameter called i, which is used
to initialize the instance variable, x. Thus, when the line
MyClass ob1(5);
executes, the value 5 is passed to i, which is then assigned to x.
18
C++ A Beginner’s Guide by Herbert Schildt