Having fun with C++’s auto_ptr

Sometimes RAII is difficult. The following code compiles without errors or warnings on Windows using Visual Studio 2005: #include <iostream> #include <memory> namespace Test { class Foo { public: bool should_do_stuff() { return false; } }; class Bar { public: Bar(std::auto_ptr<Foo> fp) : _fp(fp) {} void do_stuff() { if(_fp->should_do_stuff()) std::cout << “Do stuff” << std::endl; …

Continue reading ‘Having fun with C++’s auto_ptr’ »