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的话,这样隐式的调用就不被允许