$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] boost::enable_shared_from_this why?
From: Germán Diago (germandiago_at_[hidden])
Date: 2009-01-15 05:27:26
Hello, reading the documentation for enable_shared_from_this,
I can't understand why this kind of base class is needed. In
the example code in the documentation, we have:
class Y: public enable_shared_from_this<Y>
{
public:
    shared_ptr<Y> f()
    {
        return shared_from_this();
    }
}
int main()
{
    shared_ptr<Y> p(new Y);
    shared_ptr<Y> q = p->f();
    assert(p == q);
    assert(!(p < q || q < p)); // p and q must share ownership
}
Isn't this piece of code equivalent (since the two pointers share
ownership):
class Y
{
};
int main(int argc, char * argv[])
{
   shared_ptr<Y> p(new Y);
  shared_ptr<Y> q(p);
  ...
}