< 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;
}
Suppose that we declare two class objects,
objectA
and
objectB
:
A objectA(x);
B objectB(y, z);
a. If we write a global function
PrintIt
, defined as
void PrintIt( /* in */ A someObject )
{
someObject.Write();
}
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 >