
15 Jan
2009
15 Jan
'09
10:27 a.m.
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); ... }