December 2001
Intermediate to advanced
304 pages
6h 25m
English
auto_ptrDifficulty: 5
This Item illustrates a common pitfall with using auto_ ptr. What is the problem, and how can you solve it?
Consider the following function, which illustrates a common mistake when using auto_ptr:
template<typename T>
void f( size_t n ) {
auto_ptr<T> p1( new T );
auto_ptr<T> p2( new T[n] );
// ... more processing ...
}
What is wrong with this code? Explain.
How would you fix the problem? Consider as many options as possible, including the Adapter pattern, alternatives to the problematic construct, and alternatives to auto_ptr.
auto_ptr Don't Mix1. Consider the following function, which ...
Read now
Unlock full access