we have a function f with gets a string as below
is it safe to call this function with a const char* varialbe like belowCode:void f( std::string str )
{
// body
}
Code:void g( const char* phrase )
{
f(phrase);
}
Printable View
we have a function f with gets a string as below
is it safe to call this function with a const char* varialbe like belowCode:void f( std::string str )
{
// body
}
Code:void g( const char* phrase )
{
f(phrase);
}
Yes.
The argument is non-reference, non-pointer std::string, the object of type string will always be created even if you pass string object. Appropriate constructor would be called for initializing the function argument.
When function returns, the destructor will be called.
Thus, is it absolutely safe.