Modify
Car.cpp
so it also inherits from a class called
vehicle,
placing appropriate member functions in
vehicle
(that is, make up some member functions). Add a nondefault constructor to
vehicle,
which you must call, inside
car’s
constructor.
Create
two classes,
A
and
B,
with
default constructors that announce themselves. Inherit a new class called
C
from
A,
and create a member object of
B
in
C,
but do not create a constructor for
C.
Create an object of class
C
and
observe the results.
Use
inheritance to specialize the
PStash
class in Chapter 11 (
Pstash.h
&
Pstash.cpp)
so it accepts and returns
String
pointers. Also modify
Pstest.cpp
and test it. Change the class so
PStash
is a member object.
Use
private
and
protected
inheritance to create two new classes from a base class. Then attempt to upcast
objects of the derived class to the base class. Explain what happens.
Take
the example
ccright.cpp
in this chapter and modify it by adding your own copy-constructor
without
calling the base-class copy-constructor and see what happens. Fix the problem
by making a proper explicit call to the base-class copy constructor in the
constructor-initializer list of the
Child
copy-constructor.