Note that adding const to a return value type of a non-built-in type may make sense if you want to prevent the user of a function from accidentally doing something silly like the following:
Code:
#include <string>
std::string returnSomeString()
{
std::string result = "blah blah";
// ...
return result;
}
int main()
{
// This makes no sense! returnSomeString() returns a temporary that will
// cease to exist right after the append() method invoked on it returns. Hence
// there is no point in changing the temporary.
returnSomeString().append( "meep meep!" );
}
The following would prevent that from even compiling.
Code:
#include <string>
const std::string returnSomeString()
{
std::string result = "blah blah";
// ...
return result;
}
int main()
{
// error! this won't compile ... can't modify a constant object
returnSomeString().append( "meep meep!" );
}