
Michael Caisse wrote:
Ryan McConnehey wrote:
If class "Pool" inherits from enable_shared_from_this the documentation says I'm able to do the following.
shared_ptr<Pool> aPool = shared_from_this();
The minimal code I've included shows that this isn't happening. The code compiles but I get this error "tr1::bad_weak_ptr". What should I be doing different?
Ryan
[CODE]
//C++ Includes #include <exception> #include <iostream> #include <vector> #include <algorithm>
//Boost Includes #include
#include class pool : public boost::enable_shared_from_this< pool > { private: using boost::enable_shared_from_this< pool >::shared_from_this;
public: boost::shared_ptr<int> get(void) { boost::shared_ptr<pool> aPool = shared_from_this(); //This is where the tr1::bad_weak_ptr happens.
Ryan -
See the documentation here: http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/enable_shared_from_this....
There must be at least one shared_ptr instance that owns the object that you are calling shared_from_this() on. Also see the examples at the above link.
hth - michael
I've looked at that documentation already. That's part of why of I know I should be able to do what I want. Ryan