[   ^ to index...   |   <-- previous   ]

Thought questions

  1. In Romeo and Juliet, Juliet laments: "Romeo, Romeo/Wherefore art thou Romeo?/Deny thy father and refuse thy name! Or, if thou wilt not, be but sworn my love,/and I'll no longer be a Capulet." We can embody Juliet's problem in C++ code as follows:

    class Person { public: Person() { capuletOK = true; montagueOK = true; } bool mayMarryCapulet() { return capuletOK; } bool mayMarryMontague() { return montagueOK; } protected: bool capuletOK, montagueOK; }; class Montague : public Person { public: Montague() : Person() { capuletOK = false; } }; class Capulet : public Person { public: Capulet() : Person() { montagueOK = false; } }; Person * Romeo = new Montague; Person * Juliet = new Capulet;

    Now, when she says, "Deny thy father and refuse thy name!" she suggests the following:

    Person justAnotherGuy = *Romeo; // Make Romeo into a regular Person

    Why does this not solve her problem? What is the true solution to Juliet's problem?

    Click here for sample code...

  2. Which of the following concepts belong in an inheritance (is-a-kind-of) relationship? Which belong in containment (has-a) relationships? Which belong in instantiation (is-an-instance-of) relationships? Draw a diagram.


Last modified: Tue Jul 25 13:32:33 PDT 2000