Chapter-14 Review Questions and Exercises

------------
Short Answer
------------

1. Describe the difference between an instance member variable and a static member variable.

2. Assume that a class named Numbers has the following static member function
   declaration:
      static void showTotal();
      Write a statement that calls the showTotal function.

3. A static member variable is declared in a class.
   Where is the static member variable defined?

4. What is a friend function?

5. Why is it not always a good idea to make an entire class a friend of another class?

6. What is memberwise assignment?

7. When is a copy constructor called?

8. How can the compiler determine if a constructor is a copy constructor?

9. Describe a situation where memberwise assignment is not desirable.

10. Why must the parameter of a copy constructor be a reference?

11. What is a default copy constructor?

12. Why would a programmer want to overload operators rather than use
    regular member functions to perform similar operations?

13. What is passed to the parameter of a class's operator = function?

14. Why shouldn't a class's overloaded = operator be implemented with
    a void operator function?

15. How does the compiler know whether an overloaded ++ operator should be
    used in prefix or postfix mode?

16. What is the this pointer?

17. What type of value should be returned from an overloaded relational operator function?

18. The class Stuff has both a copy constructor and an overloaded = operator.
    Assume that blob and clump are both instances of the Stuff class.

    For each statement below, indicate whether the copy constructor or the
    overloaded = operator will be called.

        Stuff blob = clump;
        clump = blob;
        blob.operator = (clump);
        showValues(blob);       // blob is passed by value.

19. Explain the programming steps necessary to make a class's member variable static.

20. Explain the programming steps necessary to make a class's member function static.

22. Describe the difference between making a class a member of another class
    (object aggregation), and making a class a friend of another class.

23. What is the purpose of a forward declaration of a class?

24. Explain why memberwise assignment can cause problems with a class that
    contains a pointer member.

25. Why is a class's copy constructor called when an object of that class
    is passed by value into a function?

-----------------
Fill-in-the-Blank
-----------------

26. If a member variable is declared __________, all objects of that class have
    access to the same variable.

27. Static member variables are defined __________ the class.

28. A(n) __________ member function cannot access any nonstatic member variables in its own class.

29. A static member function may be called __________ any instances of its class are defined.

30. A(n) __________ function is not a member of a class, but has access to the
    private members of the class.

31. A(n) __________ tells the compiler that a specific class will be declared
    later in the program.

32. __________ is the default behavior when an object is assigned the value
    of another object of the same class.

33. A(n) __________ is a special constructor, called whenever a new object is
    initialized with another object's data.

34. __________ is a special built-in pointer that is automatically passed as
    a hidden argument to all nonstatic member functions.

35. An operator may be __________ to work with a specific class.

36. When overloading the __________ operator, its function must have a
    dummy parameter.

37. Making an instance of one class a member of another class is called __________.

38. Object aggregation is useful for creating a(n) __________ relationship
    between two classes.

39. Assume a class named Bird exists. Write the header for a member function
    that overloads the = operator for that class.

40. Assume a class named Dollars exists. Write the headers for member
    functions that overload the prefix and postfix ++ operators for that class.

41. Assume a class named Yen exists. Write the header for a member function
    that overloads the < operator for that class.

42. Assume a class named Length exists. Write the header for a member
    function that overloads cout's << operator for that class.

43. Assume a class named Collection exists. Write the header for a member
    function that overloads the [] operator for that class.

-------------
True or False
-------------

47. T F When a function is declared a friend by a class, it becomes a member of that class.

48. T F A friend function has access to the private members of the class declaring it a friend.

49. T F An entire class may be declared a friend of another class.

50. T F In order for a function or class to become a friend of another class,
        it must be declared as such by the class granting it access.

51. T F If a class has a pointer as a member, it's a good idea to also have a copy constructor.

52. T F You cannot use the = operator to assign one object's values to another
        object, unless you overload the operator.

53. T F If a class doesn't have a copy constructor, the compiler generates
        a default copy constructor for it.

54. T F If a class has a copy constructor, and an object of that class is
        passed by value into a function, the function's parameter will
        not call its copy constructor.

55. T F The this pointer is passed to static member functions.

56. T F All functions that overload unary operators must have a dummy parameter.

57. T F For an object to perform automatic type conversion, an operator function must be written.

58. T F It is possible to have an instance of one class as a member of another class.