Question: 3. (The Smart Pointer std::auto_ptr) This pointer type is deprecated in C++11. Consider the following code: using std::auto_ptr; // Define auto_ptr pointers instead of raw
3. (The Smart Pointer std::auto_ptr)
This pointer type is deprecated in C++11. Consider the following code:
using std::auto_ptr;
// Define auto_ptr pointers instead of raw pointers std::auto_ptr
// Dereference *d = 2.0;
// Change ownership of auto_ptr // (after assignment, d is undefined)
auto_ptr
*d2 = 3.0;
cout << "Auto values: " << *d.get() << ", " << *d2.get();
Answer the following questions:
a) Type the above code and run it. Why does it give a run-time error?
b) Port the code to code that uses std::unique_ptr. Run and test the new code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
