-
const question
In the following function definition what does the final const refer to?
const Stock & Stock::topval(const Stock & s) const
The first const refers to this obect passed implicitly correct?
The second const refers to s passed explicitly correct?
Looking at it makes me think the first const refers to the return type and the last to the implicitly passed object.
Just a little confused help!
-
const Stock & Stock::topval(const Stock & s) const
topval is a const [3rd] member function of Stock, taking a const [2nd] stock by reference, and returning a reference to a const [1st] stock.
The final const means that data cannot be modified (with the exception of mutable data, but you can pretty much forget about that) within the member function. const member functions can call other const member functions, but not non-const member functions.
-
Thanks for the informative answer :)