From 04851b7e5f85ea3705345aa6fe9a6436df902100 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 13 Apr 2014 08:38:06 +0200 Subject: [PATCH] add auto_ptr.cpp --- auto_ptr.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 auto_ptr.cpp diff --git a/auto_ptr.cpp b/auto_ptr.cpp new file mode 100644 index 0000000..a60fcae --- /dev/null +++ b/auto_ptr.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() { + int *i = new int; + std::auto_ptr x(i); + std::auto_ptr y; + /* Note: auto_ptr is deprecated. */ + + y = x; + + std::cout << x.get() << std::endl; // Print NULL + assert(x.get() == NULL); + std::cout << y.get() << std::endl; // Print non-NULL address i + assert(y.get() != NULL); + + return 0; +}