Why unique-ptr doesn't check base class to virtual destructible?

后端 未结 2 796
日久生厌
日久生厌 2020-12-13 20:51

Consider this example :

#include 
#include 

struct base
{
    base( int i ): i(i)    {    printf(\"base ctor\\n\"); }
    ~base(         


        
2条回答
  •  旧巷少年郎
    2020-12-13 21:18

    Not all unique_pointers are used polymorphically:

    std::unique_ptr p(new int(42));
    

    This would not compile with the restriction you propose. Same with classes:

    std::unique_ptr p(new YourClassHere);
    

提交回复
热议问题