MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Exercises

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru