September 2017
Beginner to intermediate
384 pages
8h 4m
English
The auto_ptr smart pointer takes a raw pointer, wraps it, and ensures the memory pointed by the raw pointer is released back whenever the auto_ptr object goes out of scope. At any time, only one auto_ptr smart pointer can point to an object. Hence, whenever one auto_ptr pointer is assigned to another auto_ptr pointer, the ownership gets transferred to the auto_ptr instance that has received the assignment; the same happens when an auto_ptr smart pointer is copied.
It would be interesting to observe the stuff in action with a simple example, as follows:
#include <iostream>#include <string>#include <memory>#include <sstream>using namespace std;class MyClass { private: static int count; string name; public: MyClass() { ostringstream ...