I was reading an article about effectively using auto_ptr. In there, the following code was suggested as a correct piece of code:
// Example 10(c): Correct (finally!)
//
auto_ptr<String> f()
{
auto_ptr<String> result = new String;
*result = "some value";
cout << "some output";
return result; // rely on transfer of ownership;
// this can't throw
}
But as far as I am aware, the assignment operator of auto_ptr only accepts another auto_ptr as the rhs -- to avoid accidental misuse. So, is the following line a typo in the article, or is it really suppposed to work?
auto_ptr<String> result = new String;