What does this mean "string ret(v);" in the code below?
char t(char c)
{
return tolower(c);
}
string toLower(const string & v)
{
string ret(v);
transform(ret.begin(), ret.end(), ret.begin(), t);
return ret;
}
What does this mean "string ret(v);" in the code below?
char t(char c)
{
return tolower(c);
}
string toLower(const string & v)
{
string ret(v);
transform(ret.begin(), ret.end(), ret.begin(), t);
return ret;
}
What does this mean
string ret(v);
[...]?
This creates a copy of the function argument v
with the name ret
. This copy is then altered by the call to std::transform
and returned by value.
Note that v
is passed as a const
-qualified reference. It can't be changed within the function. That's why a copy is made to create a string object that can be modified an returned to the caller as a result.