#include #include #include #include using std::cout; using std::endl; using std::ostream; using std::unique_ptr; void Leaky() { int *x = new int(5); // heap-allocated cout << *x << endl; } // never called delete, therefore leaked typedef struct { int x = 1, y = 2; } Point; ostream& operator<<(ostream &out, const Point &rhs) { return out << "(" << rhs.x << "," << rhs.y << ")"; } void NotLeaky() { unique_ptr p(new Point); // wrapped, heap-allocated p->x = 5; cout << *p << endl; } // never called delete, but no leak int main(int argc, char **argv) { Leaky(); NotLeaky(); return EXIT_SUCCESS; }