Is using std::vector< std> > an antipattern?

后端 未结 4 1426
醉话见心
醉话见心 2020-12-29 22:22

For a long time I was using std::vector and std::shared_ptr hand in hand. Recently I started using std::shared_ptr when

4条回答
  •  清歌不尽
    2020-12-29 23:01

    1 The problem is not related to shared_ptr<>, but occurs already for ordinary pointers:

    template
    void foo(std::vector);
    
    int a,b;
    std::vector bar={&a,&b};
    foo(bar);        // no value for ??? works
    

    2 The construct vector> is sensibly only iff there is no owner to the objects hold.

提交回复
热议问题