| View previous topic :: View next topic |
| Author |
Message |
qazmlp Guest
|
Posted: Sun Mar 07, 2004 12:52 pm Post subject: returning copy of the temporary string object |
|
|
Is this code reliable? Basically, I want to know whether returning
copy of the temporary string object is valid or not.
#include <iostream>
std::string returnString()
{
return std::string( "TempString" ) ;
}
int main()
{
std::cout<< returnString() << std::endl;
}
|
|
| Back to top |
|
 |
Jeff Schwab Guest
|
Posted: Sun Mar 07, 2004 12:59 pm Post subject: Re: returning copy of the temporary string object |
|
|
qazmlp wrote:
| Quote: | Is this code reliable? Basically, I want to know whether returning
copy of the temporary string object is valid or not.
#include
std::string returnString()
{
return std::string( "TempString" ) ;
}
int main()
{
std::cout<< returnString() << std::endl;
}
|
Yep, that's fine.
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sun Mar 07, 2004 1:01 pm Post subject: Re: returning copy of the temporary string object |
|
|
"qazmlp" <qazmlp1209 (AT) rediffmail (DOT) com> wrote
| Quote: | Is this code reliable? Basically, I want to know whether returning
copy of the temporary string object is valid or not.
#include
std::string returnString()
{
return std::string( "TempString" ) ;
}
int main()
{
std::cout<< returnString() << std::endl;
}
|
Yes completely reliable.
john
|
|
| Back to top |
|
 |
Claudio Puviani Guest
|
Posted: Sun Mar 07, 2004 4:57 pm Post subject: Re: returning copy of the temporary string object |
|
|
"qazmlp" <qazmlp1209 (AT) rediffmail (DOT) com> wrote
| Quote: | Is this code reliable? Basically, I want to know whether returning
copy of the temporary string object is valid or not.
#include
std::string returnString()
{
return std::string( "TempString" ) ;
}
int main()
{
std::cout<< returnString() << std::endl;
}
|
It's reliable in Standard C++. I've seen Microsoft Visual C++ crash while trying
to do that. A fair (and rhetorical question) would be, "Is Visual C++ reliable?"
:-)
Claudio Puviani
|
|
| Back to top |
|
 |
|