Is this code safe? Just because it runs with no errors, I'm concerned I'm setting a trap for myself.
void targetMethod( const char *arg );
std::string helperMethod( char *text ) { return std::string( text ); }
targetMethod( helperMethod().c_str() );
helperMethod() returns a std::string, and the calling code gets its underlying char*, and passes it to targetMethod(). I'm concerned that the returned string is temporary, so taking its underlying char* is dangerous. So instead I should do something like this:
std::string myTemp = helperMethod( "hello" );
targetMethod( myTemp.c_str() );