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

Exercises

  1. Create a class that holds an array of ints. Set the size of the array using an untagged enumeration inside the class. Add a const int variable, and initialize it in the constructor initializer list. Add a static int member variable and initialize it to a specific value. Add a static member function that prints the static data member. Add an inline constructor and an inline member function called print( ) to print out all the values in the array, and to call the static member function.
  2. In StaticDestructors.cpp, experiment with the order of constructor and destructor calls by calling f( ) and g( ) inside main( ) in different orders. Does your compiler get it right?
  3. In StaticDestructors.cpp, test the default error handling of your implementation by turning the original definition of out into an extern declaration and putting the actual definition after the definition of A (whose obj constructor sends information to out). Make sure there’s nothing else important running on your machine when you run the program or that your machine will handle faults robustly.
  4. Create a class with a destructor that prints a message and then calls exit( ). Create a global static object of this class and see what happens.
  5. Modify Volatile.cpp from Chapter 6 to make comm::isr( ) something that would actually work as an interrupt service routine.

Contents | Prev | Next


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