< previous page page_184 next page >

Page 184
LISTING 12.3 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
23:         itsAge = 1;
24:  }
25:
26:  SimpleCat::SimpleCat(SimpleCat&)
27:  {
28:         cout << Simple Cat Copy Constructor\n;
29:  }
30:
31:  SimpleCat::~SimpleCat()
32:  {
33:         cout << Simple Cat Destructor\n;
34:  }
35:
36:  const     SimpleCat & FunctionTwo (const SimpleCat & theCat);
37:
38:  int main()
39:  {
40:         cout << Making a cat\n;
41:         SimpleCat Frisky;
42:         cout << Frisky is  << Frisky.GetAge() <<  years old\n;
43:         int age = 5;
44:         Frisky.SetAge(age);
45:         cout << Frisky is  << Frisky.GetAge() <<  years old\n;
46:         cout << Calling FunctionTwo\n;
47:         FunctionTwo(Frisky);
48:         cout << Frisky is  << Frisky.GetAge() <<  years old\n;
49:         return 0;
50:  }
51:
52:  // functionTwo passes a ref to a const object
53:  const SimpleCat & FunctionTwo (const SimpleCat & theCat)
54:  {
55:         cout << Function Two. Returning\n;
56:         cout << Frisky is now  << theCat.GetAge();
57:         cout <<  years old \n;
58:         // theCat.SetAge(8);  const!
59:         return theCat;
60:  }

Output:
Making a cat
Simple Cat constructor
Frisky is 1 years old
Frisky is 5 years old
Calling FunctionTwo
FunctionTwo. Returning
Frisky is now 5 years old
Frisky is 5 years old
Simple Cat Destructor

 
< previous page page_184 next page >

If you like this book, buy it!