Hello all:
I have read that the purpose of const member functions is to specify which functions may be used on const objects. This makes sense.
An example is given in my text and I don't understand it. If anyone could help, I would be very grateful.
Here is the example:
Using const in function declarations can reduce errors without compromising safety or efficiency. For example, recall the declaration of operator* for the Wood class:
const Wood operator*(const Wood& lhs, const Wood& rhs);
Why should the return type be const? Otherwise, you could write code like this:
Wood a, b, c; (a * b) = c;
This would not be allowed by a built-in type. Making operator* return const disallows this for the Wood type too.
This is probably a dumb question, but I don't understand what is wrong with writing code like: Wood a, b, c; (a * b) = c;
Thanks
Can can anyone explain?