Smart pointers in container like std::vector?

后端 未结 5 2009
你的背包
你的背包 2020-12-05 11:02

I am learning about smart pointers (std::auto_ptr) and just read here and here that smart pointers (std::auto_ptr) should not be put in containers

5条回答
  •  执念已碎
    2020-12-05 11:20

    For classes that have an auto ptr data member, I always have a clone method that returns a new auto ptr. I then implement an assignment method and copy constructor that call the clone method (and never the default assignment operator of auto ptr). This way you can safely use the class in STL containers.

提交回复
热议问题