|
|
|
|
|
|
|
Q Given the problems with overloaded functions, why not always use default values instead? |
|
|
|
|
|
|
|
|
A Overloaded functions supply capabilities not available with default variables, such as varying the list of parameters by type rather than just by number. |
|
|
|
|
|
|
|
|
Q When writing a class constructor, how do you decide what to put in the initialization and what to put in the body of the constructor? |
|
|
|
|
|
|
|
|
A A simple rule of thumb is to do as much as possible in the initialization phase; that is, initialize all member variables there. Some things, like computations and print statements, must be in the body of the constructor. |
|
|
|
|
|
|
|
|
Q Can an overloaded function have a default parameter? |
|
|
|
|
|
|
|
|
A Yes. There is no reason not to combine these powerful features. One or more of the overloaded functions can have their own default values, following the normal rules for default variables in any function. |
|
|
|
|
|