How do I use unique_ptr for pimpl?

后端 未结 2 747
终归单人心
终归单人心 2020-11-29 03:12

Here is a simplification of what I\'m seeing when I try to use unique_ptr for pimpl. I chose unique_ptr because I really want the class to own the pointer - I want the life

2条回答
  •  天命终不由人
    2020-11-29 04:03

    Note this from unique_ptr definition:

    std::unique_ptr may be constructed for an incomplete type T, such as to facilitate the use as a handle in the pImpl idiom. If the default deleter is used, T must be complete at the point in code where the deleter is invoked, which happens in the destructor, move assignment operator, and reset member function of std::unique_ptr.

提交回复
热议问题