Item 21. An Unmanaged Pointer Problem, Part 2: What About auto_ptr?

I l @ ve RuBoard

Item 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?

  1. 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.

  2. 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 // // In some header file: void f( auto_ptr<T1>, auto_ptr<T2> ); // In some implementation file: f( auto_ptr_new<T1>(), auto_ptr_new<T2>() ); 
I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net