August 2001
Beginner
482 pages
10h 52m
English
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 needed—perhaps the user wants to supply either the width or the height, but not both—it is easy to extend the overloaded functions. The default value, however, will quickly become too complex to use 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 differing types in your parameter list.
Read now
Unlock full access