N
Noah Roberts
I am wordering if there is any difference between these two statements:
std::string functionX()
{
char buf[256];
... do stuff;
return string(buf);
}
std::string functionX()
{
char buf[256];
... do stuff;
return buf;
}
Both are acceptable to my compiler so obviously it is smart enough to
know I want buf translated to a string. However, my question relates to
what happens in this case:
std::string x = functionX();
In both cases the char* has to be converted to a string, but is the copy
constructor also called in both cases or is it smart enough to call the
conversion and assign it directly to string 'x'? Are there any unseen
problems with either definition of functionX?
NR
std::string functionX()
{
char buf[256];
... do stuff;
return string(buf);
}
std::string functionX()
{
char buf[256];
... do stuff;
return buf;
}
Both are acceptable to my compiler so obviously it is smart enough to
know I want buf translated to a string. However, my question relates to
what happens in this case:
std::string x = functionX();
In both cases the char* has to be converted to a string, but is the copy
constructor also called in both cases or is it smart enough to call the
conversion and assign it directly to string 'x'? Are there any unseen
problems with either definition of functionX?
NR