Vector as a class member

后端 未结 4 1317
醉梦人生
醉梦人生 2020-12-15 13:36

Hello I have this question: I would like to have a vector as class member. This is perhaps my question easier for you and I apologize for that.

  • how should I de
4条回答
  •  长情又很酷
    2020-12-15 14:19

    That depends entirely on context - what the vector means and why you need it. Should it be shared among multiple objects? If you don't know, don't keep a pointer, go with your second option.

    std::vector myVector;
    

    If you have strong reasons to have a pointer, then please use a smart pointer, the one that provides most appropriate ownership for your situation - shared_ptr, scoped_ptr, unique_ptr or whatever_ptr

提交回复
热议问题