class B
{
public:
    virtual ~B(){}
};

class D : public B
{
public:
    D(){}
protected:
    virtual ~D(){}
};

int main()
{
    D d;                // Illegal.

    B *pD = new D;      // Ok.
    delete pD;
    pD = NULL;

    return 0;
}

  As you see, the key is to disable create local variable by prtected access in class D, and call the dtor through polymorphism.

相关文章:

  • 2021-07-28
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-19
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
相关资源
相似解决方案