|
Thinking In C++. Volume 2: Practical ProgrammingВ В В В В В В В В В В Modify the Instrument hierarchy from Chapter 14 of Volume 1 by first copying Wind5.cpp to a new location. Now add a virtual ClearSpitValve(В ) function to the Wind class, and redefine it for all the classes inherited from Wind. Instantiate a TStash to hold Instrument pointers, and fill it with various types of Instrument objects created using the new operator. Now use RTTI to move through the container looking for objects in class Wind, or derived from Wind. Call the ClearSpitValve(В ) function for these objects. Notice that it would unpleasantly confuse the Instrument base class if it contained a ClearSpitValve(В ) function. 9: Multiple inheritance The basic concept of multiple inheritance (MI) sounds simple enough: you create a new type by inheriting from more than one base class. The syntax is exactly what you’d expect, and as long as the inheritance diagrams are simple, MI can be simple as well. Or maybe not! MI can introduce a number of ambiguities and strange situations, which are covered in this chapter ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|