Q:

For each of the three following declarations of combine, explain what happens if we call i.combine(s), where i is a Sales_data and s is a string

0

For each of the three following declarations of combine, explain what happens if we call i.combine(s), where i is a Sales_data and s is a string:

(a) Sales_data &combine(Sales_data);

(b) Sales_data &combine(Sales_data&);

(c) Sales_data &combine(const Sales_data&) const;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

(a) `Sales_data &combine(Sales_data);` The code works correct. It will first convert `s` to `Sales_data`, then copy that temporary into the parameter of `combine`.

(b) `Sales_data &combine(Sales_data&);` The code is wrong. It will first convert `s` to `Sales_data`, then pass the reference to that temporary into the parameter of `combine`, but passing a reference to a temporary is error.

(c) `Sales_data &combine(const Sales_data&) const;` The code could not compile, because it should not be a const member function. It will first convert `s` to `Sales_data`, then pass the const reference to that temporary into the parameter of `combine`.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now