警告: deleting object of polymorphic class type which has non_virtual destructor
生活随笔
收集整理的这篇文章主要介绍了
警告: deleting object of polymorphic class type which has non_virtual destructor
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
如果基类里有虚函数,定义了基类指针指向派生类,就会需要定义基类虚析构,这样,基类指针析构的时候,就会先析构派生类,再析构基类。
在用基类指针指向派生类时,
在基类析构函数声明为virtual的时候,delete基类指针,会先调用派生类的析构函数,再调用基类的析构函数。
在基类析构函数没有声明为virtual的时候,delete基类指针,只会调用基类的析构函数,而不会调用派生类的析构函数,这样会造成销毁对象的不完全。
转载于:https://www.cnblogs.com/amwuau/p/9149938.html
总结
以上是生活随笔为你收集整理的警告: deleting object of polymorphic class type which has non_virtual destructor的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Supervisor进程管理开机自启
- 下一篇: 校招准备-科研