
Hi All, I'm new to Boost, and I've been taking a look at scoped pointers. Here's the example from the boost documentation: ---------------------------------------------------------------------- #include <boost/scoped_ptr.hpp> #include <iostream> struct Shoe { ~Shoe() { std::cout << "Buckle my shoe\n"; } }; class MyClass { boost::scoped_ptr<int> ptr; public: MyClass() : ptr(new int) { *ptr = 0; } int add_one() { return ++*ptr; } }; int main() { boost::scoped_ptr<Shoe> x(new Shoe); MyClass my_instance; std::cout << my_instance.add_one() << '\n'; std::cout << my_instance.add_one() << '\n'; } ---------------------------------------------------------------------- I notice that the creation of a new object for the scoped pointer has been done before the MyClass constructor. However you can't declare the scoped pointer as a member variable and then do something like this in a method: protected: scoped_pointer<ArbitaryObject> mPointerToObject; .... // Later mPointerToObject ( new ArbitaryObject() ); Why is that? Thanks! -- View this message in context: http://www.nabble.com/scoped_ptr-initialization-tp19431388p19431388.html Sent from the Boost - Users mailing list archive at Nabble.com.