Main Page

Previous Page
Next Page

[Page 568 (continued)]

Self-Review Exercises


Fill in the blanks in each of the following:

  1. __________ must be used to initialize constant members of a class.

  2. A nonmember function must be declared as a(n) __________ of a class to have access to that class's private data members.

  3. The __________ operator dynamically allocates memory for an object of a specified type and returns a __________ to that type.

  4. A constant object must be __________; it cannot be modified after it is created.

  5. A(n) __________ data member represents class-wide information.

  6. An object's non-static member functions have access to a "self pointer" to the object called the __________ pointer.

  7. The keyword __________ specifies that an object or variable is not modifiable after it is initialized.

  8. If a member initializer is not provided for a member object of a class, the object's __________ is called.

  9. A member function should be declared static if it does not access __________ class members.

  10. Member objects are constructed __________ their enclosing class object.

  11. The __________ operator reclaims memory previously allocated by new.


Find the errors in the following class and explain how to correct them:

  class Example
     Example( int y = 10 )
        : data( y )
        // empty body
     } // end Example constructor

     int getIncrementedData() const
        return data++;
     } // end function getIncrementedData

[Page 569]
static int getCount() { cout << "Data is " << data << endl; return count; } // end function getCount private: int data; static int count; }; // end class Example

Previous Page
Next Page