Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2004-10-15 18:21:40


On 10/14/2004 09:52 AM, Oleg Fedtchenko wrote:
[snip]
> we must specify an owner every time and easily can
> pass in a shared_ptr other than pointing to the right
> owner:
>
> shared_ptr<A> pA(new A);
>
> shared_ptr<SOME> pSome(new SOME);
>
> shared_ptr<B> pB = pA->GetB( pSome);
>
Could you define a new shared_ptr templated CTOR which takes a pointer
to member:

    template<typename Member>
    struct shared_ptr
    {
       template<typename Owner, Member Owner::*pm_type>
       shared_ptr(shared_ptr<Owner>* a_owner, pm_type a_pm)
       : px(a_owner.get()->a_pm), pn(???)
       {}
    };

I haven't compiled this; hence, the syntax may not be right.
How would this compare with member_ptr, and the others?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk