You can, but you don't need to.
Code:
const std::string Help2()
{
return "";
}
void Help()
{
std::string s = Help2();
}
Visual Studio completely ignores the const there since it's a return-by-value. The Help function can use it however much it wants, but it cannot actually modify the original string that's returned (since it's return-by-value).
Following also works:
Code:
const std::string& Help2()
{
static std::string s = "";
return s;
}
void Help()
{
std::string s = Help2();
}
Following does not work:
Code:
const std::string& Help2()
{
static std::string s = "";
return s;
}
void Help()
{
std::string& s = Help2(); // Add const and it will compile
}