`
vearne
  • 浏览: 18285 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

has virtual functions but non-virtual destructor

 
阅读更多

 

#include <iostream>
using namespace std;
class based{
public:
	based(){
	}
	~based(){
		 cout<<"flag 1"<<endl;
	}
	virtual void f(){
		cout<<"ok1"<<endl;
	}
};
class derived:public based{

public:
	~derived(){
		cout<<"flag 2"<<endl;
	}
	void f(){
		cout<<"ok2"<<endl;
	}
};
int main(){
based* p = new derived();
p->f();
delete p;
	
}

 

输出结果:

ok2

flag 1

 

指向基类的指针,delete p;只调用基类的析构函数,没有调用派生类的析构函数。

 

分享到:
评论

相关推荐

    Selected.Topics.in.Cplusplus.15117

    Then you have virtual functions and virtual tables and virtual pointers. When you know these core concepts C++ becomes a powerful language to use because you can control your program to do exactly ...

    game-destructor:由GitHub Classroom创建的game-destructor

    game-destructor:由GitHub Classroom创建的game-destructor

    Google C++ Style Guide(Google C++编程规范)高清PDF

    We can declare (but not define) functions with arguments, and/or return values, of type Foo. (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor, in which ...

    Cookie DestrucTor-开源

    Cookie DestructoR可帮助您维护网络隐私。 该软件具有即时清除Cookie和Internet缓存的功能。 如有必要,可以销毁计算机上的Index.dat数据库文件。

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX TTreeInspector.FDelimBmp don't removed in destructor. - FIX TFlexPanel.FIsOverSegment flag take into account now the pen width. - ADD TFlexEllipse.Center - read-only public property. - FIX Trial...

    Computer Destructor-开源

    这是你应该完全拥有它的最棒的 pwogwam eva! 啊啊啊啊

    windowsmain directx device font virtual button dll array 0.3

    Library file destructor-free version He's an example of a C-function

    ruby-destructor:Ruby 的析构函数

    gem 'destructor' 然后执行: $ bundle 或者自己安装: $ gem install destructor 用法 require 'destructor' class Foo attr_reader :bar def initialize @bar = 123 end def finalize puts ...

    delphi2-delphi2010 全支持 dcu 装换 pas

    But if a record has any variant parts in it, the typed const may can't correctly decompile * Function/procedure type declaration - Support threadvar - Support resourcestring - Support class type...

    陈广C#程序设计入门与实例视频教程11-19.rar

    11-constructor(2).swf 12-Destructor(1).swf 13-Destructor(2).swf 14-decstructor(3).swf 15-modifier.swf 16-Conversions(1).swf 17-Conversions(2).swf 18-Property(1).swf 19-Property(2).swf

    windowsmain directx device font virtual button dll array 0.4

    The library file has a destructor version.this is a windowsmain library.

    C模式设计:C中的实用设计模式

    用生成的目录设计模式C中的实用设计模式这将是在C中实现GoF (四人制)的设计模式。 (第1版)提供脚本以自动将设计模式生成为不同的代码样式:C,...+ +destructor virtual +methods virtual + + routine + + +

    Ugly-as-Sin:GZDoom mod Hideous Destructor的增强模块

    丑如罪 的mod,添加了各种可选功能和机制。 最初以HD-Scavenger开头,专注于长期的“生存”功能,但后来Swift扩展为通用增强型mutator。 特征 通常将功能实现为具有各种可自定义设置的可切换模块。...

    C++中确定基类有虚析构函数

    本文给大家介绍了C++中确定基类有虚析构函数的方法。

    Effective+C+++3rd+chm+中文版(代码加亮)

    destructor(析构函数)什么时候应该是 virtual(虚拟)的?当 operator new(运算符 new)找不到足够的内存时它应该怎么办?类似这些的令人费神的细节是至关重要的,因为错误的做法几乎总是导致无法预料的,很可能...

    PAF:cpp的最简单的可插入抽象工厂

    #PAF可插拔抽象工厂让我们看一个简单的用法我有一个接口,它的实现如下,带有方法栏: // interface fileclass foo_i {public: // no need virtual destructor virtual int bar() = 0;}// class fileclass foo : ...

    kdev_t.rar_Inherited

    Message is not intended to be inherited from. In particular, its destructor is not virtual.

    Delphi 关键字详解

    absolute //它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同. var Str: string[32]; StrLen: Byte absolute Str; //这个声明指定了变量... destructor Destroy; override; published end;

    Delphi最新三层源码

    destructor Destroy; override; procedure AfterConstruction; override; property PClassName: TClass read getClassName write setClassName; property POLEData: OleVariant read GetOLEData write SetOLEData; ...

    C#程序设计基础教程与实训_12.destructor(1)

    初学者在学习程序的过程中很重要的一个学习方法就是读源代码,但如果对语言本身的了解不够,在阅读源码的过程中会遇到很大的困难。磨刀不误砍柴功,制作《C#语言参考视频》教程的目的在于帮助初学者打下坚实的语言...

Global site tag (gtag.js) - Google Analytics