std::auto_ptr or boost::shared_ptr for pImpl idiom?

后端 未结 9 1346
醉梦人生
醉梦人生 2020-12-23 15:04

When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of a std::auto_ptr? I\'m sure I once read that the boost version is

9条回答
  •  生来不讨喜
    2020-12-23 15:59

    boost::shared_ptr is specially tailored to work for pimpl idiom. One of the main advantages is that it allows not to define the destructor for the class holding pimpl. Shared ownership policy maybe both advantage and disadvantage. But in later case you can define copy constructor properly.

提交回复
热议问题