|
|
|
|
|
|
|
If UseCurrentValue is false, either because it has defaulted false or was set by the user, the first two parameters are used for setting printWidth and printHeight. |
|
|
|
|
|
|
|
|
Note that if UseCurrentValue is true, the values of the other two parameters are completely ignored. |
|
|
|
|
|
|
|
|
Choosing Between Default Values and Overloaded Functions |
|
|
|
|
|
|
|
|
Listings 13.1 and 13.2 accomplish the same thing, but the overloaded functions in 13.1 are simpler to understand and more natural to use. Also, if a third variation is neededperhaps the user wants to supply either the width or the height, but not bothit is easy to extend the overloaded functions. The default value, however, will quickly become unusably complex as new variations are added. |
|
|
|
|
|
|
|
|
How do you decide whether to use function overloading or default values? Here's a rule of thumb: |
|
|
|
|
|
|
|
|
Look to function overloading when |
|
|
|
|
|
|
|
|
There is no reasonable default value. |
|
|
|
|
|
|
|
|
You need different algorithms. |
|
|
|
|
|
|
|
|
You need to support variant types in your parameter list. |
|
|
|
|
|
|
|
|
As discussed in Hour 6, Classes, if you do not explicitly declare a constructor for your class, a default constructor is created that takes no parameters and does nothing. You are free to make your own default constructor, however, that takes no arguments but that sets up your object as required. |
|
|
|
|
|
|
|
|
The constructor provided for you is called the default constructor, but, by convention, so is any constructor that takes no parameters. This can be a bit confusing, but it is usually clear from context what is meant. |
|
|
|
|
|
|
|
|
Take note that if you make any constructors at all, the default constructor is not made by the compiler. So if you want a constructor that takes no parameters, and you've created any other constructors, you must make the default constructor yourself! |
|
|
|
|
|