9.1 Fill in the blanks in each of the following:
Class members are accessed via the operator in conjunction with the name of an object (or reference to an object) of the class or via the operator in conjunction with a pointer to an object of the class.
Class members specified as are accessible only to member functions of the class and friend
s of the class.
class members are accessible anywhere an object of the class is in scope.
can be used to assign an object of a class to another object of the same class.
A nonmember function must be declared by the class as a(n) of a class to have access to that class’s private
data members.
A constant object must be ; it cannot be modified after it’s created.
A(n) data member represents classwide information.
An object’s non-static
member functions have access to a “self pointer” to the object called the pointer.
Keyword specifies that an object or variable is not modifiable.
If a member initializer is not provided for a member object of a class, the object's is called.
A member function should be static
if it does not access class members.
Member objects are constructed their enclosing class object.
When a member function is defined outside the class definition, the function header must include the class name and the , followed by the function name to “tie” the member function to the class definition.
9.2 Find the error(s) in each of the following and explain how to correct it (them):
Assume the following prototype is declared in class Time
:
void ~Time(int);
Assume the following prototype is declared in class Employee
:
int Employee
(string, string);
The following is a definition of class Example
:
class Example {
public:
Example(int y = 10) : data(y) { }
int getIncrementedData() const {
return ++data;
}
static int getCount() {
cout << "Data is " << data << endl;
return count;
}
private:
int data;
static int count;
};