Sams Teach Yourself C++ in 21 Days

(singke) #1
6: CAT(int age) { itsAge = age; }
7: ~CAT(){}
8: int GetAge() const { return itsAge;}
9: private:
10: int itsAge;
11: };
12:
13: CAT & MakeCat(int age);
14: int main()
15: {
16: int age = 7;
17: CAT Boots = MakeCat(age);
18: cout << “Boots is “ << Boots.GetAge()
19: << “ years old” << endl;
20: return 0;
21: }
22:
23: CAT & MakeCat(int age)
24: {
25: CAT * pCat = new CAT(age);
26: return *pCat;
27: }


  1. Fix the program from Exercise 8.


288 Day 9

Free download pdf