Linux后台服务器编程。
分类: C/C++
2014-10-30 14:59:33
The header
enable_shared_from_this
class Y: public enable_shared_from_this{ public: shared_ptr f() { return shared_from_this(); } } int main() { shared_ptr p(new Y); shared_ptr q = p->f(); assert(p == q); assert(!(p < q || q < p)); // p and q must share ownership }
namespace boost { templateclass enable_shared_from_this { public: shared_ptr shared_from_this(); shared_ptr shared_from_this() const; } }
Requires: enable_shared_from_this
must be an accessible base class of T. *this must be a subobject of an instance t of type T . There must exist at least one shared_ptr instance p that owns t. Returns: A shared_ptr
instance r that shares ownership with p. Postconditions: r.get() == this.