How to approach copying objects with smart pointers as class attributes?

后端 未结 5 593
小鲜肉
小鲜肉 2021-01-02 16:15

From the boost library documentation I read this:

Conceptually, smart pointers are seen as owning the object pointed to, and thus responsible for de

5条回答
  •  有刺的猬
    2021-01-02 16:20

    I've never heard about ready-to-use realisation, but you can simply do it by yourself.

    First of all your should write some template wrapper class which has virtual clone method, returning copy of stored object. And then write some polymophic holder of that class which would be copyable

    and don't forget about checked delete http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Checked_delete

提交回复
热议问题