std::shared_ptr alias constructor

    struct X
    {
        int a;
    };
    shared_ptr<X> px(new X);
    shared_ptr<int> pi(px, &px->a); 

    shared_ptr<X> sp1(new X);
    shared_ptr<X> sp2(sp1, new X); // ERROR: delete for this X will never be called

    sp1.reset(); // deletes first X; makes sp1 empty
    shared_ptr<X> sp3(sp1, new X); // use_count()==0, but get()!=nullptr

 

posted @ 2020-05-31 13:50  P.wang  阅读(171)  评论(0编辑  收藏  举报