GCO4020/CSC428 - Advanced Object Oriented Techniques In C++
Week 5

 

Topic 9: Envelopes and Letters

Exercises


Synopsis


Exercise 1

Explain why the Value class stores string values in a separate data member (myVal_String) rather than in the PolyType union (myVal).

There is a sample solution for Exercise 1.


Exercise 2

Suggest other member/friend functions which might be appropriate for class Value.

There is a sample solution for Exercise 2.


Exercise 3

Explain why ValueLet::convertToBool() does not (need to) take a ValueLet*& as a parameter.

There is a sample solution for Exercise 3.


Exercise 4

Explain why, in ValueLet::assign(), is is necessary to delete letter_ref before reassigning it. Suggest any restrictions this deletion places on the way assign() is written.

There is a sample solution for Exercise 4.


Exercise 5

Describe the steps that would be required to add the capacity to store objects of the STL¤ class complex<double>:

  1. inside a Value

  2. inside a ValueEnv

There is a sample solution for Exercise 5.


Exercise 6

Trace the following code fragment and verify that you understand the workings of the ValueEnv envelope and its various letter classes:

ValueEnv v1(true); ValueEnv v2("cat");

v2 += ++v1;

ValueEnv v3(3); ValueEnv v4(4.4);

v3 += v4;

There is a sample solution for Exercise 6.


Exercise 7

Explain why the Null helper class is needed. That is, explain why it is not possible to simply use ValueType<void> as the "null" letter type.

There is a sample solution for Exercise 7.


Exercise 8

The ValueType::Val() member function was introduced to avoid the need for universal friendship between the various interacting specializations¤ of ValueType. Describe how such a mutual friendship could be established between every possible ValueType<T> class.

There is a sample solution for Exercise 8.


Exercise 9

List the benefits of re-implementing the letter classes as a single template.

There is a sample solution for Exercise 9.


Exercise 10

With the addition of the templated ValueType letter class, describe the steps that would now be required to add to the ValueEnv class the capacity to store objects of the STL¤ class complex<double>.

There is a sample solution for Exercise 10.


Exercise 11

  1. Explain how you could use a member template to allow the ValueEnv class to store values of any type (without additional coding for each type).

  2. List the limitations of this approach.

There is a sample solution for Exercise 11.

 


This material is part of the GCO4020/CSC428 - Advanced Object Oriented Techniques In C++ course.
Copyright © Damian Conway, 1997. All rights reserved.

Last updated: Fri Feb 18 11:17:41 2000