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