"Gaijinco" <ga******@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Yeah, if you input carlos it would output solrac but there is something
quite odd, this works fine:
void inverse(string s, int pos, int size)
{
if(pos==size-1)
{
cout << s;
return s;
}
else
{
int idx = s.size()-1;
char character = s.at(idx);
s.erase(idx);
s.insert(s.begin()+pos,character);
inverse(s,pos+1,size);
}
}
But if I try to return the string, then the program crashes. I'm not
sure why is that!
You defined the function as void, but then have a "return s" statement in
the first part.
If it is supposed to return a string, then define it to return a string.
And then you also need a return statement for the else condition. (Probably
"return inverse(s,pos+1,size):"? I haven't tested the thought.)
If it is not supposed to return a string, then it should be operating on s
directly, and never returning a value. In that case, make s a string&
instead, and change "return s;" to just "return;".
-Howard