How do I use unique_ptr for pimpl?

后端 未结 2 736
终归单人心
终归单人心 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 03:42

    I believe that your test_help.cpp actually sees the ~Help() destructor that you declared default. In that destructor, the compiler tries to generate the unique_ptr destructor, too, but it needs the Impl declaration for that.

    So if you move the destructor definition to the Help.cpp, this problem should be gone.

    -- EDIT -- You can define the destructor to be default in the cpp file, too:

    Help::~Help() = default;
    

提交回复
热议问题