Chapter 21. An Unmanaged Pointer Problem, Part 2: What About auto_ptr?
Difficulty: 8
Does using auto_ptr
help to solve the problem in Item 20?
As you continue to root through the archives, you see that someone must not have liked Item 20 Example 20-2 because later versions of the files in question were changed as follows:
// Example 21-1 // // In some header file: void f( auto_ptr<T1>, auto_ptr<T2> ); // In some implementation file: f( auto_ptr<T1>( new T1 ), auto_ptr<T2>( new T2 ) );
What improvements does this version offer over Item 20 Example 20-2, if any? Do any exception safety problems remain? Explain.
Demonstrate how to write an
auto_ptr_new
facility that solves the safety problems in Question 1 and can be invoked as follows:// Example 21-2 ...
Get More Exceptional C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.