-
Specify the set of values and the set of operations
provided by each of the following C++ built-in data types:
- char,
- int,
- double, and
- string.
-
What are the features of C++ that
facilitate the creation of user-defined data types.
-
Explain how each of the following
C++ features supports polymorphism:
- operator overloading,
- templates, and
- inheritance.
-
Suppose we define two concrete classes, A and B,
both of which are derived from the Object class
declared in Program .
Furthermore, let a and b be instances of
classes A and B (respectively) declared as follows:
class A : public Object { ... };
class B : public Object { ... };
A a;
B b;
Give the sequence of functions called in order to evaluate
a comparison such as ``a<b''.
Is the result of the comparison true or false?
Explain. -
Consider the Wrapper<T> class defined in Program .
Explain the operation of the following program fragment:
int i = 5;
Wrapper<int> j = 7;
i = j;
j = i;
-
There are three ways to test whether a given object instance,
obj, is the null object:
- obj.IsNull ()
- obj == NullObject::Instance (), and
- &obj == &(NullObject::Instance ()).
Discuss the relative merits of each approach. -
Let c be an instance of some concrete class
derived from the Container class
given in Program .
Explain how the statement
cout << c;
prints the contents of the container
on the standard output stream, cout. -
Suppose we have a container c
(i.e., an instance of some concrete class
derived from the Container class
defined in Program )
which among other things happens to contain itself.
Is it permissible for c to own the objects it contains?
What happens when c's destructor runs
if it owns the objects it contains.
-
Iterators and visitors provide two ways to do the same thing--to visit one-by-one all the objects in a container.
Give an implementation for the Accept function
of the Container class that uses an iterator.
-
Is it possible to implement an iterator using a visitor?
Explain.
-
Suppose we have a container which we know contains only
instances of the Int class defined in Program .
Design a Visitor which computes the sum of all the integers
in the container.
-
Explain what the following visitor does
and why it is a horribly bad idea:
class DeletingVisitor : public Visitor
{
public:
void Visit (Object& object)
{ delete &object; }
};
-
Consider the following pair of Associations:
Association a (*new Int (3), *new Int (4));
Association b (*new Int (3));
Give the sequence of functions called in order to evaluate
a comparison such as ``a==b''.
Is the result of the comparison true or false?
Explain.