Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Apr 26, 2015
1 parent 5b2a043 commit d64f05c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ch07/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ 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.)
(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.)
(c) Sales_data &combine(const Sales_data&) const; // The trailing const mark can't be put here, as it forbids any mutation on data members. This comflicts with combine's semantics.
```
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))
Expand Down

0 comments on commit d64f05c

Please sign in to comment.