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

Exercises

  1. Create a class called bird that can fly( ) and a class rock that can’t. Create a rock object, take its address, and assign that to a void*. Now take the void*, assign it to a bird*, and call fly( ) through that pointer. Is it clear why C’s permission to openly assign via a void* is a “hole” in the language?
  2. Create a class containing a const member that you initialize in the constructor initializer list and an untagged enumeration that you use to determine an array size.
  3. Create a class with both const and non- const member functions. Create const and non- const objects of this class, and try calling the different types of member functions for the different types of objects.
  4. Create a function that takes an argument by value as a const; then try to change that argument in the function body.
  5. Prove to yourself that the C and C++ compilers really do treat constants differently. Create a global const and use it in a constant expression; then compile it under both C and C++.
Contents | Prev | Next


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