std::string getMyString() { return <make a string>; } ... HANDLE something = OpenSomething(getMyString().c_str(), ...);
I read the Guaranteed lifetime of a temporary in C ++ , and I believe that the temporary string will live until the assignment is evaluated, i.e. enough to do this work as expected.
Once before starting a std::stringlifecycle related error (I don't remember what it was), I would prefer to double check ...
std::string
Yes, that’s fine. :-)
The line will be destroyed at the end of the instruction in half-pitch.
, , , .
, char*, - , OpenSomething , .
char*
OpenSomething
Unless you use any other argument OpenSomthingto return a pointer to getMyString.c_str(), everything will be fine.
OpenSomthing
getMyString.c_str()