首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ Primer 练习题请问 (第四版, 14.3)

2012-03-05 
C++ Primer 练习题请教 (第四版, 14.3)C++Primer第四版有这样一个问题,不理解,请高手指教Exercise14.3:Exp

C++ Primer 练习题请教 (第四版, 14.3)
C++   Primer   第四版有这样一个问题,   不理解,   请高手指教

Exercise   14.3:  
Explain   the   following   program,   assuming   that   the   Sales_item   constructor   that   takes   a   string   is   not   explicit.   Explain   what   happens   if   that   constructor   is   explicit.

          string   null_book   =   "9-999-99999-9 ";
          Sales_item   item(cin);
          item   +=   null_book;

不胜感激

[解决办法]
注意这个语句 item += null_book;
[解决办法]
item += null_book;//这里会调用构造函数用null_book生成一个临时Sale_Item对象

如果构造函数是explicit的话,这样隐式的调用就不被允许

热点排行