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

Exercises

  1. Create a struct declaration with a single member function; then create a definition for that member function. Create an object of your new data type, and call the member function.
  2. Write and compile a piece of code that performs data member selection and a function call using the this keyword (which refers to the address of the current object).
  3. Show an example of a structure declared within another structure (a nested structure ). Also show how members of that structure are defined.
  4. How big is a structure? Write a piece of code that prints the size of various structures. Create structures that have data members only and ones that have data members and function members. Then create a structure that has no members at all. Print out the sizes of all these. Explain the reason for the result of the structure with no data members at all.
  5. C++ automatically creates the equivalent of a typedef for enumerations and unions as well as structs, as you’ve seen in this chapter. Write a small program that demonstrates this.

Contents | Prev | Next


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