< previous page page_202 next page >

Page 202
LISTING 13.3 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
19:  };
20:
21:  CAT::CAT()
22:  {
23:       itsAge = new int;
24:       itsWeight = new int;
25:       *itsAge = 5;
26:       *itsWeight = 9;
27:  }
28:
29:  CAT::CAT(const CAT & rhs)
30:  {
31:       itsAge = new int;
32:       itsWeight = new int;
33:       *itsAge = *rhs.itsAge;
34:       *itsWeight = *rhs.itsWeight;
35:  }
36:
37:  CAT::~CAT()
38:  {
39:       delete itsAge;
40:       itsAge = 0;
41:       delete itsWeight;
42:       itsWeight = 0;
43:  }
44:
45:  int main()
46:  {
47:       CAT frisky;
48:       cout << frisky's age:  << frisky.GetAge() << endl;
49:       cout << Setting frisky to 6\n;
50:       frisky.SetAge(6);
51:       cout << Creating boots from frisky\n;
52:       CAT boots(frisky);
53:       cout << frisky's age:  << frisky.GetAge() << endl;
54:       cout << boots' age:  << boots.GetAge() << endl;
55:       cout << setting frisky to 7\n;
56:       frisky.SetAge(7);
57:       cout << frisky's age:  << frisky.GetAge() << endl;
58:       cout << boot's age:  << boots.GetAge() << endl;
59:       return 0;
60:  }

 
< previous page page_202 next page >

If you like this book, buy it!