/* CSE 333 Su12 lecture 13 demo: autoexample1.cc */ /* Gribble/Perkins */ // Basic use of auto_ptr. Compare valgrind output with // and without call to function Leaky. #include // for std::cout, std::endl #include // for std::auto_ptr #include // for EXIT_SUCCESS void Leaky() { int *x = new int(5); // heap allocated (*x)++; std::cout << *x << std::endl; } void NotLeaky() { std::auto_ptr x(new int(5)); // wrapped, heap-allocated (*x)++; std::cout << *x << std::endl; } int main(int argc, char **argv) { Leaky(); NotLeaky(); return EXIT_SUCCESS; }