R
Raider
What is returned objects life-time?
For example, is it safe:
#include <...>
std::string foo()
{
return std::string("foo");
}
std::string bar()
{
std::string bar("bar");
return bar;
}
void test(char* a, char* b)
{
....
}
int main()
{
test(foo().c_str(), bar().c_str());
}
Here I think might be a problem. foo() returns std::string objects,
c_str() returns some pointer into the std::string("foo") and passes
this pointer to the test(). But will std::string("foo") exist when
test() is executed?
For example, is it safe:
#include <...>
std::string foo()
{
return std::string("foo");
}
std::string bar()
{
std::string bar("bar");
return bar;
}
void test(char* a, char* b)
{
....
}
int main()
{
test(foo().c_str(), bar().c_str());
}
Here I think might be a problem. foo() returns std::string objects,
c_str() returns some pointer into the std::string("foo") and passes
this pointer to the test(). But will std::string("foo") exist when
test() is executed?