/* CSE 333 Su12 lecture 13 demo: scopedexample.cc */ /* Gribble/Perkins */ // Example using a boost scoped_ptr, automatically // freed when it goes out of scope (or is deleted) #include #include class MyClass { public: MyClass(int *p) : sptr_(p) { } private: boost::scoped_ptr sptr_; }; int main(int argc, char **argv) { // initialize a scoped_ptr to contain an (int *) boost::scoped_ptr x(new int(10)); // mc's constructor initializes the scoped_ptr in the sptr_ member // variable to contain sevenptr. int *sevenptr = new int(7); MyClass mc(sevenptr); return EXIT_SUCCESS; }