- 浏览: 389185 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 15284首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 964RPath is a very interesting to ... -
C++ - autogenerated copy constructor and assignment operator gotchas
2013-01-24 13:32 744It has been changed that the s ... -
c++ - rethrow a exception gotchas
2012-12-23 10:57 919As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1031typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 735There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 783we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 913As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 721There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 930Let's see what if we want to cl ... -
c++ - vritual function and default arguments
2012-09-27 08:56 950As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1285in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 902class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 956template class may defined thei ... -
c++ - Friend declaration in class Template
2012-09-25 08:47 1180There are three kinds of friend ... -
c++ - class template default parameters
2012-09-25 08:18 800the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 553The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1133In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 837A class member operator new() c ... -
c++ - overloaded subscript operator - []
2012-09-23 08:50 1126You can overload the subscript ...
相关推荐
[麻省理工学院-算法导论].Introduction.to.Algorithms.-.Instructor's.Manual
[麻省理工学院-算法导论].Introduction.to.Algorithms.-.Instructor&-#39;s.Manual.rar
[麻省理工学院-算法导论].Introduction.to.Algorithms.-.Instructor's.Manual 算法导论-教师手册 讲义
麻省理工学院 算法导论 Introduction.to.Algorithms Instructor.Manual
这是麻省理工学院的一本算法导论书,对于想学习算法和研究算法的人来说是很值得借鉴的一本书,里面有很多的算法思想。
HP-UX System and Network Fundermental-Instructor Guide-1147.pdf
The instructor's manual for the book C++ How to Program
HyperMesh基础培训-INSTRUCTOR-PPT-SLIDE_2020_V2.zip
Instructor's Manual + Solutions
《深入理解计算机系统》课后习题答案- Instructor's Solution Manual
solutions to CSAPP homework
David I. Schneider - Instructor Solutions Manual for An Introduction to Programming Using Python (2016, Pearson).pdf
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
大学4年收集了不少好的电子书,这些都是经典中的经典,没什么好说的,快下载吧。 我的资源,你们可以转载。对于书籍,其版权归原书作者。 源代码,你们可以修改完善,二次开发。 计算机的书最好看国外的...
一款用来学习计算机网络实验的模拟工具,为设计、配置、排除网络故障提供了网络模拟环境。 用户可以在软件的图形用户界面上直接使用拖曳方法建立网络拓扑,并可提供数据包在网络中行进的详细处理过程,观察网络实时...
JavaScript 103指令评估 是时候看看我们对您在JavaScript中进行事件处理的教导有多好。 设置 ... 链接到名为eventHandling.jsJavaScript文件中。 ... 您将使用element.classList来操作element.classList上CSS类。...
AIX AU13 课程培训资料,教学用书。
czi-stats-instructor-resources 使用统计和数据科学的教师资源:一种建模方法。 这些资源旨在通过访问其网站来使用。 该存储库用于存储资源文件和用于构建站点的文件。 如果您想贡献您的资源或想修复网站上的错误...