The compiler decides which method to call based on the number and type of parameters
entered. You can imagine a third overloaded function named DrawShape()that takes one
dimension and an enumeration for whether it is the width or height, at the user’s choice.
Using Default Values ..........................................................................................
Just as global functions can have one or more default values, so can each member func-
tion of a class. The same rules apply for declaring the default values, as illustrated in
Listing 10.2.
LISTING10.2 Using Default Values
1: //Listing 10.2 Default values in member functions
2: #include <iostream>
3:
4: using namespace std;
5:
6: // Rectangle class declaration
7: class Rectangle
8: {
9: public:
10: // constructors
11: Rectangle(int width, int height);
12: ~Rectangle(){}
13: void DrawShape(int aWidth, int aHeight,
14: bool UseCurrentVals = false) const;
15:
16: private:
17: int itsWidth;
18: int itsHeight;
19: };
20:
21: //Constructor implementation
22: Rectangle::Rectangle(int width, int height):
23: itsWidth(width), // initializations
24: itsHeight(height)
25: {} // empty body
26:
27:
28: // default values used for third parameter
29: void Rectangle::DrawShape(
30: int width,
31: int height,
32: bool UseCurrentValue
33: ) const
34: {
292 Day 10