- The following is one possible answer:
SimpleCircle::SimpleCircle(const SimpleCircle & rhs)
{
int val = rhs.GetRadius();
itsRadius = new int(val);
} - The following is one possible answer:
SimpleCircle& SimpleCircle::operator=(const SimpleCircle & rhs)
{
if (this == &rhs)
return this;
delete itsRadius;
itsRadius = new int;
itsRadius = rhs.GetRadius();
return *this;
} - The following is one possible answer:
1: #include
2: using namespace std;
3:
4: class SimpleCircle
5: {
6: public:
7: // constructors
8: SimpleCircle();
9: SimpleCircle(int);
10: SimpleCircle(const SimpleCircle &);
11: ~SimpleCircle() {}
12:
13: // accessor functions
14: void SetRadius(int);
15: int GetRadius()const;
16:
17: // operators
18: const SimpleCircle& operator++();
19: const SimpleCircle operator++(int);
20: SimpleCircle& operator=(const SimpleCircle &);
21:
22: private:
23: int *itsRadius;
24: };
25:
26:
27: SimpleCircle::SimpleCircle()
28: {itsRadius = new int(5);}
29:
30: SimpleCircle::SimpleCircle(int radius)
31: {itsRadius = new int(radius);}
840 Appendix D
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 840