c++ primer 6.5.1节练习答案

练习6.40

a)正确

b)错误,一旦某个形参被赋予了默认值,他后面的所有形参都必须有默认值。

练习6.41

a)错误,ht没有默认实参,而a的实参列表里也没有给出实参;

b)合法,调用init(24 ,10 ,‘ ’);

c)虽然合法,但是与程序猿的设计初衷不符,*会转换成十进制的数43,相当于调用init(14, 43, ‘ ’);

练习6.42

 1 string make_plural(size_t ctr, const string &word, const string &ending = "s")
 2 {
 3     return (ctr > 1) ? word + ending : word;
 4 }
 5 
 6 int main()
 7 {
 8     cout << make_plural(2, "success", "es") << endl;
 9     cout << make_plural(1, "success") << endl;
10     cout << make_plural(2, "failure") << endl;
11     cout << make_plural(1, "failure") << endl;
12     system("pause");
13     return 0;
14 }

 

posted @ 2017-08-03 20:14  五月份小姐  阅读(303)  评论(0编辑  收藏  举报