|
|
 |
|
|
|
|
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: } |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|