#include <iostream> // for std::cout, std::endl #include <memory> // for std::auto_ptr #include <stdlib.h> // for EXIT_SUCCESS void Leaky() { int *x = new int(5); // heap allocated (*x)++; std::cout << *x << std::endl; } void NotLeaky() { std::auto_ptr<int> x(new int(5)); // wrapped, heap-allocated (*x)++; std::cout << *x << std::endl; } int main(int argc, char **argv) { Leaky(); NotLeaky(); return EXIT_SUCCESS; }