简体   繁体   中英

C++ smart vector with smart pointers?

Learning smart pointers and stumble upon this problem: How would I create a vector with objects that auto deletes themselves? Below is a snippet of how I have it at the moment, is this the correct way to ensure I don't need to call delete on anything?

unique_ptr<vector<unique_ptr<OBJ>>> list(new vector<unique_ptr<OBJ>>);

H.Guijt指出了在向量本身上调用new的冗余,下面的代码应该足够了:

vector<unique_ptr<Entry>> list;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM