This is the function I have in a .h file:
static std::string ReturnString(std::string some_string)
return ("\t<" + some_string + " ");
The compiler (g++ -std=c++0x -pedantic -Wall -Wextra) throws these errors:
error:expected identifier before '(' token
error:named return values are no longer supported
error:expected '{' at end of input
warning: no return statement in function returning non-void [-Wreturn-type]
But,
static std::string ReturnString(std::string some_string)
{
return ("\t<" + some_string + " ");
}
works fine. Even,
static std::string ReturnString(std::string some_string)
{
return "\t<" + some_string + " ";
}
works too.
Could someone please explain this to me please? Am I missing some basic knowledge of strings?
Thanks.
static std::string ReturnString(std::string some_string)
return ("\t<" + some_string + " ");
It's actually a basic knowledge of C++ that you're missing. In C++, function bodies must be enclosed in curly braces, {}
. So, the correct definition for the function above would be:
static std::string ReturnString(std::string some_string)
{
return ("\t<" + some_string + " ");
}