< previous page page_963 next page >

Page 963
A::A( /* in */ char ch )
{
    c = ch;
}

void A::Write() const
{
    cout << c;
}

B::B( /* in */ char ch1,
      /* in */ char ch2 )

    : A(ch1 )
{
    d = ch2;
}
void B::Write() const
{
    A::Write();
    cout << d;
}
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Suppose that we declare two class objects, objectA and objectB:
A objectA(x);
B objectB(y, z);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. If we write a global function PrintIt, defined as
void PrintIt( /* in */ A someObject )
{
    someObject.Write();
}
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
then what is printed by the following code segment?
PrintIt(objectA);
cout << endl;
PrintIt(objectB);
b. Repeat part (a), assuming that PrintIt uses pass-by-reference instead of passby-value:
void PrintIt( /* in */ A& someObject )
{
    someObject.Write();
}
c. Repeat part (b), assuming that Write is not a. virtual function.

 
< previous page page_963 next page >