// smrtptrs.cpp -- using three kinds of smart pointers #include #include #include class Report { private: std::string str; public: Report(const std::string s) : str(s) { std::cout << "Object created!\n"; } ~Report() { std::cout << "Object deleted!\n"; } void comment() const { std::cout << str << "\n"; } }; int main() { { std::auto_ptr ps (new Report("using auto_ptr")); ps->comment(); // use -> to invoke a member function } { std::shared_ptr ps (new Report("using shared_ptr")); ps->comment(); } { std::unique_ptr ps (new Report("using unique_ptr")); ps->comment(); } // std::cin.get(); return 0; }