How to attach boost::shared_ptr (or another smart pointer) to reference counter of object's parent?

Posted by Checkers on Stack Overflow See other posts from Stack Overflow or by Checkers
Published on 2010-05-03T00:56:37Z Indexed on 2010/05/03 1:08 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

I remember encountering this concept before, but can't find it in Google now.

If I have an object of type A, which directly embeds an object of type B:

class A {
    B b;
};

How can I have a smart pointer to B, e. g. boost::shared_ptr<B>, but use reference count of A? Assume an instance of A itself is heap-allocated I can safely get its shared count using, say, enable_shared_from_this.

© Stack Overflow or respective owner

Related posts about boost

Related posts about c++