I just wrote a function:
void doSomeStuffWithTheString(const std::string& value) {
...
std::string v = value;
std::cout << value.c_str();
...
}
but then I call it with
doSomeStuffWithTheString("foo");
and it works. Therefore, I would think that to work (const char * to initialize an implicit instance of std :: string), the value must be passed by value, but in this case it is passed by reference (const).
Is randomly implicit temporary std :: string created from const char * when the link is const? if not, how is it possible to work?
EDIT
what happens if a function is overloaded with
void doSomeStuffWithTheString(const char* value);
which one will the compiler choose?
source
share