How to declare a vector of unique_ptr's as class data member?

后端 未结 5 1290
借酒劲吻你
借酒劲吻你 2021-02-20 11:26

I\'d like to have a vector of unique_ptr\'s as a member of a class I\'m making.

class Foo {
    [...]

private:
    vector> barList;
         


        
5条回答
  •  日久生厌
    2021-02-20 12:01

    You can't use unique_ptr in vector because vector implementation strongly relies on values assign operator, which is private in unique_ptr. Use shared_ptr from boost or other smart ptr implementation from C++11.

提交回复
热议问题