Say I want to write a function like this:
int get_some_int(string index) {
...perform magic...
return result;
}
However, I also want to be able to call it like this:
int var = obj.get_some_int("blah");
However, I can’t do this as const char[4] is not const string&
I could do:
int get_some_int(char* index) {
...perform magic...
return result;
}
But this spews out a lot of warnings, implying it’s not how it should be done.
What is the correct way to handle string arguments then?
No, but
std::stringhas a non-explicitconversion constructor so a temporarystd::stringis created, so you’re in the clear. – http://ideone.com/xlg4k