So I have this code:
void blocks(std::string URL, std::string auth)
{
const char* cstr_url = URL.c_str();
std::string s = ("Authorization: " + auth);
const char* auth_header = s.c_str();
(··· and so on ···)
}
And everything seems fine if we look in the "autos" field in Debug mode:
But if we try to change the code in a way that ("Authorization: " + auth)
is a temporary instance of the String class, in order to avoid declaring the s
variable (and therefore saving space -at least, that's my purpose-):
void blocks(std::string URL, std::string auth)
{
const char* cstr_url = URL.c_str();
const char* auth_header = ("Authorization: " + auth).c_str();
(··· and so on ···)
}
...what we get in the Debug "autos" field is something quite different (lots of Ý chars):
I thought C++ could support these kind of things (which I don't know how are they technically called, I assume "implicit instance" as an original name). I would swear Java could support these "implicit instances" though.
So the actual question is, what's happening in here? Is there any workaround to avoid declaring an s
variable?