#include // for std::unique_ptr #include // for EXIT_SUCCESS using namespace std; typedef struct { int a, b; } IntPair; int main(int argc, char **argv) { unique_ptr x(new int(5)); // Return a pointer to the pointed-to object int *ptr = x.get(); // Return the value of the pointed-to object int val = *x; // Access a field or function of a pointed-to object unique_ptr ip(new IntPair); ip->a = 100; // Deallocate the pointed-to object and reset the unique_ptr with // a new heap-allocated object. x.reset(new int(1)); // Release responsibility for freeing the pointed-to object. ptr = x.release(); delete ptr; return EXIT_SUCCESS; }