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

Exercises

  1. Use RTTI to assist in program debugging by printing out the exact name of a template using typeid( ). Instantiate the template for various types and see what the results are.
  2. Implement the function TurnColorIfYouAreA( ) described earlier in this chapter using RTTI.
  3. Modify the Instrument hierarchy from Chapter XX 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 up with various types of Instrument objects created using new. 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.
Contents | Prev | Next


Contact: webmaster@codeguru.com
CodeGuru - the website for developers.
[an error occurred while processing this directive]