I think he means something like this, two different member functions:
Code:
class A {
public:
const std::string &someFunc();
std::string &someOtherFunc() const;
};
The difference is that "someFunc" returns a const reference to a string and someOtherFunc returns a non-const reference to a string. Another difference is that "someOtherFunc" doesn't let you modify the object for which this function is a member, and that "someFunc" can not be called on a const object.
So: const after the function declaration means that it is possible to call the function when the object is const, though it makes sure you never change the object, at least not whatever you aren't allowed to change.
For instance:
Code:
A a;
const A aConst;
a.someFunc(); // Legal: call on non-const object to a function that doesn't take a const object.
a.someOtherFunc(); // Legal: const function called on non-const object; this object will become const in someOtherFunc.
aConst.someFunc(); // Illegal: someFunc() requires a non-const object, but a const object was passed.
aConst.someOtherFunc(); // Legal: aConst is a const object, so it's fine to call a function making it const.
So whenever you make a function that doesn't change the object, you should always make it const. That is completely unrelated to a const returned value, the following is perfectly legal and very common:
Code:
const std::string &someFunction() const;