如下例:

class Base
{
public:
    
virtual foo() = 0;
protected:
    
virtual ~Base(){};
};

class Derived
{
public:
    Derived(string str) : _str(str){}
    
virtual foo(){ //.. }
protected:
    
string _str;
}


这时,如果有
Base *p = new Derived("some string");
//...
delete p;

这时,不能调用析构函数

相关文章:

  • 2021-11-18
  • 2021-08-22
  • 2021-10-08
  • 2022-01-30
  • 2021-06-25
  • 2021-10-09
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
相关资源
相似解决方案