- 浏览: 399953 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
As we all know that virtual destructor is an essential part of object lifecycle management. so without further adieu, let first see the examples.
class Query { protected: virtual ~Query(); }; class NotQuery : public Query { public : virtual ~NotQuery(); };
it complies with the pattern of the virutal function and about inheritance, where you declared the functions that are supposed to be changed as protected section, and also, you make the destructor as virual so that you can call the appropriate destructor based on the real object that is pointed by the pointer or reference.
Now, let's see the example on how to use the virtual destructor based on what we already have now.
#include "virtual_destructor.h" void demo_virtual_constructor() { Query *pq = new NotQuery(); // illegal , destructor is protected delete pq; }
now we see that there is error with the code above.
Now let'se see a revised version.
class Query1 { public: virtual ~Query1(); }; class NotQuery1 : public Query1 { public: virtual ~NotQuery1(); };
and with this , the code will works file.
* As a general rule of thumb, we recommend that the root base clas of a class hierarchy declaring one or more virtual destructors virtual as well. * However, unlike the base class constructor, the base destructor, in general, should not be made protected. */ void demo_virtual_constructor1() { Query1 *pq = new NotQuery1(); delete pq; }
发表评论
-
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15342首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 1012RPath is a very interesting to ... -
C++ - autogenerated copy constructor and assignment operator gotchas
2013-01-24 13:32 772It has been changed that the s ... -
c++ - rethrow a exception gotchas
2012-12-23 10:57 964As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1060typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 773There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 824we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 978As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 754There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 960Let's see what if we want to cl ... -
c++ - vritual function and default arguments
2012-09-27 08:56 994As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1330in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 939class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 986template class may defined thei ... -
c++ - Friend declaration in class Template
2012-09-25 08:47 1212There are three kinds of friend ... -
c++ - class template default parameters
2012-09-25 08:18 855the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 588The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1170In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 874A class member operator new() c ... -
c++ - overloaded subscript operator - []
2012-09-23 08:50 1188You can overload the subscript ...
相关推荐
这本书的"Instructor's Manual"(教师手册)则是为授课教师提供的辅助材料,旨在帮助他们更好地理解和传授书中的算法概念。 **算法基础** 算法是解决问题或执行任务的明确、有限的步骤序列。它们在计算机科学中扮演...
Instructor's Manual是该书的教师指南,提供了课程教学的详细指导和支持。下面将详细阐述这本书中的关键知识点。 1. **算法基础**:算法是解决问题或执行任务的明确步骤序列,是计算机科学的核心。书中首先介绍了...
Instructor's Manual是配套的教学指导手册,为教师提供了丰富的教学资源和解题指导,帮助学生更好地理解和应用书中的算法。 算法是计算机科学的基础,是解决问题的关键工具。《算法导论》涵盖了排序、搜索、图算法...
讲师手册(Instructor's Manual)作为配套资源,通常包含了解题指导、习题解答和教学建议,对于学习者和教师来说都是非常宝贵的参考资料。 在“解析的比较经典,比起国内的强的多,强调思考”这一描述中,我们可以...
《C++ How To Program (Instructor's Manual)》是一本为教授C++编程语言而编写的教师指南。这本书是《C++ How to Program》的第三版的配套教学手册,由Deitel、Deitel & Nieto合作编写,由Deitel & Associates, Inc....
《算法导论》是计算机科学领域的一本经典教材,由麻省理工学院的专家们编著,被广泛用于全球各大高校的教学。教师手册是专为教授这门课程的教师准备的,提供了深入的教学指导和补充材料,以帮助教师更好地理解和传授...
solidworks
HP-UX System and Network Fundermental-Instructor Guide-1147.pdf
#### MIT - Introduction to Algorithms - Instructor's Manual **标题解析:** 这份文档名为“MIT - Introduction to Algorithms - Instructor's Manual”,它指的是由麻省理工学院(MIT)出版的一本关于算法介绍...
HyperMesh基础培训-INSTRUCTOR-PPT-SLIDE_2020_V2.zip
Instructor's Manual是配套的教学指南,包含了对书中习题的解答,对于学习者来说是极其宝贵的资源。 这本书涵盖了许多关键的计算机科学概念,包括: 1. **二进制和数字系统**:介绍二进制、十六进制和八进制表示法...
根据给定的信息,我们可以从《C++ How to Program》这本教材中提炼出一系列重要的知识点。下面将逐一介绍这些知识点,并结合教材的部分内容进行详细解释。 ### 一、计算机编程入门与C++语言概述 #### 知识点: 1. ...
- **文档类型:** 教师指南(Instructor Guide) - **认证材料版本:** ERC6.0 - **提供方:** IBM Learning Services - **版权:** © Copyright International Business Machines Corporation 1995, 2001. All rights ...
QNET DCMCT - Workbook (Instructor)是一本为教师准备的教材,它包含了演示程序和详尽的设置过程,目的是让教师能够教授学生如何使用LabVIEW来控制电机。在LabVIEW环境中,用户可以通过虚拟仪器(Virtual Instruments...
udacity-show-instructor-notes-above-player udacity-show-instructor-notes-above-player 是一个 Chrome 扩展,用于将 Udacity 的教师笔记移动到视频播放器上方。 它可在 Chrome 网上应用店免费获得,网址为 ...
Linear Algebra and Its Applications David C. Lay -- Instructor's Matlab Manual 3rd Ed
一款用来学习计算机网络实验的模拟工具,为设计、配置、排除网络故障提供了网络模拟环境。 用户可以在软件的图形用户界面上直接使用拖曳方法建立网络拓扑,并可提供数据包在网络中行进的详细处理过程,观察网络实时...
JavaScript 103指令评估 是时候看看我们对您在JavaScript中进行事件处理的教导有多好。 设置 ... 链接到名为eventHandling.jsJavaScript文件中。 ... 您将使用element.classList来操作element.classList上CSS类。...
北京语言大学(BLCU)在2011年秋季...综上所述,BLCU-Fall2011-Smalltalk-Instructor-开源项目的教学材料涵盖了面向对象编程的基本原则,Smalltalk语言及其Squeak实现,以及如何在教育领域应用这一技术进行模拟和创新。