Hw #2
Ch 14
Review Questions and Exercises, P 879: 1, 7, 10, 20, 38, 43, 45, 52, 60, 62;
Programming Challenges, P 884: 4, 5, 6.
Describe the difference between an instance member variable and a static member variable.
The main difference between an instance member variable and a static member variable is each class object has its own copy of class’s instance member variables. If a class’s member variable is static, however, only one instance of the variable exists in memory. All objects of that class have access to that one variable.
7. When is a copy constructor called?
Copy constructor is a special constructor that is called whenever a new object is created and initialized with another object’s data.
10. Why must the parameter of a copy constructor be a reference?
…show more content…
To do that you make a copy, and to do that you call the copy constructor. But to do that, we need to make a new value, so we call the copy constructor
20. Explain the programming steps necessary to make a class’s member function static.
1. Place the key word static before the member function’s prototype.
2. After that place a separate definition of the variable outside the class.
38. Object aggregation is useful for creating a(n) has a relationship between two classes.
43. Assume a class named Collection exists. Write the header for a member function that overloads the [] operator for that class.
Given class name;
Collection
The header for a member function that overloads the [] operator for that class: void Collection:: &operator[](constant Collection &sub)
45. T F Static member variables are defined outside their class declaration.
52. T F You cannot use the = operator to assign one object’s values to another object, unless you overload the operator.
60. class