
----- Original Message ----- From: "Emil Dotchevski" <emildotchevski@gmail.com> To: <boost@lists.boost.org> Sent: Wednesday, March 04, 2009 12:17 AM Subject: Re: [boost] Boost.Convert+Boost.Parameter
By the way, returning std::string doesn't guard against such errors:
std::string to_string( foo const & ); foo bar(); char const * s=to_string(bar()).c_str(); //oops.
Here the problem is not that to_string returns a string but using c_str(). The same problem occurs when you use c_str on a local string. When the string goes out of scope the data pointeed by the recovred c_str is bad. char* ext; { std::string str("local"); //.. ext=str.c_str(); // } // Here ext points to a free memory area // if ext.is used the code coudl not work. Best, Vicente