Chapter 8

1: What kinds of functions are good candidates for inline status?
A1: Short, non-recursive functions that can fit in one line of code.
2: Suppose the song() function has this prototype:
void song(char * name, int times);
  1. How would you modify the prototype so that the default value for times is 1?

  2. What changes would you make in the function definition?

  3. Can you provide a default value of “O, My Papa” for name?

A2:
  1. void song(char * name, int times = 1);

  2. None. Only prototypes contain the default value information.

  3. Yes, providing you retain the default value for times:

    void song(char * name = "O, My Papa", int times = 1);
    
3: Write overloaded versions of iquote(), a function that displays its argument enclosed in double quotation marks. Write ...

Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.