|
|
|
|
|
|
|
LISTING 13.1 AN ILLUSTRATION OF OVERLOADING MEMBER FUNCTIONS |
|
|
|
 |
|
|
|
|
1: //Listing 13.1 Overloading class member functions
2: #include <iostream.h>
3:
4: // Rectangle class declaration
5: class Rectangle
6: {
7: public:
8: // constructors
9: Rectangle(int width, int height);
10: ~Rectangle(){}
11:
12: // overloaded class function DrawShape
13: void DrawShape() const;
14: void DrawShape(int aWidth, int aHeight) const;
15:
16: private:
17: int itsWidth;
18: int itsHeight;
19: };
20:
21: //Constructor implementation
22: Rectangle::Rectangle(int width, int height)
23: {
24: itsWidth = width;
25: itsHeight = height;
26: }
27:
28:
29: // Overloaded DrawShape - takes no values
30: // Draws based on current class member values
31: void Rectangle::DrawShape() const
32: {
33: DrawShape( itsWidth, itsHeight);
34: }
35:
36:
37: // overloaded DrawShape - takes two values
38: // draws shape based on the parameters
39: void Rectangle::DrawShape(int width, int height) const
40: {
41: for (int i = 0; i<height; i++)
42: {
43: for (int j = 0; j< width; j++)
44: {
45: cout << *;
46: }
47: cout << \n;
48: }
49: } |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|