Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocxs committed Mar 13, 2015
1 parent 4493cd1 commit 6117690
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions ch07/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,9 @@ Both are noting happened.
```cpp
(a) Sales_data &combine(Sales_data); // ok
(b) Sales_data &combine(Sales_data&); // [Error] no matching function for call to 'Sales_data::combine(std::string&)' (`std::string&` can not convert to `Sales_data` type.)
//It's wrong. Because combine’s parameter is a non-const reference , we can't pass a temporary to that parameter. If combine’s parameter is a reference to const , we can pass a temporary to that parameter. Like this :Sales_data &combine(const Sales_data&); Here we call the Sales_data combine member function with a string argument. This call is perfectly legal; the compiler
automatically creates a Sales_data object from the given string. That newly generated (temporary) Sales_data is passed to
combine.
(c) Sales_data &combine(const Sales_data&) const; // [Error] assignment of member 'Sales_data::units_sold' in read-only object. (we cannot combine the other `Sales_data` object.)
```
Some detailed explanation about problem (b) :It's wrong. Because combine’s parameter is a non-const reference , we can't pass a temporary to that parameter. If combine’s parameter is a reference to const , we can pass a temporary to that parameter. Like this :`Sales_data &combine(const Sales_data&); ` Here we call the `Sales_data` combine member function with a string argument. This call is perfectly legal; the compiler automatically creates a `Sales_data` object from the given string. That newly generated (temporary) `Sales_data` is passed to combine.(Also you can read C++ Primer Page 295(English Edition))
## [Exercise 7.50](ex7_50.h)
## Exercise 7.51
Expand Down

0 comments on commit 6117690

Please sign in to comment.