Q&A

Q1:Why would you ever use default values when you can overload a function?
A1: It is easier to maintain one function than two, and often easier to understand a function with default parameters than to study the bodies of two functions. Furthermore, updating one of the functions and neglecting to update the second is a common source of bugs.
Q2:Given the problems with overloaded functions, why not always use default values instead?
A2: Overloaded functions supply capabilities not available with default variables, such as varying the list of parameters by type rather than just by number.
Q3: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?
A3: 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.
Q4:Can an overloaded function have a default parameter?
A4: 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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.157.142