Item 7: declare Destructors (destructor) as virtual in polymorphic base classes (polymorphism base class)
By Scott Meyers
Translator: fatalerror99 (itepub's nirvana)
Release: http://blog.csdn.net/fatalerror99/
There are many ways to get the time, so
Reference: http://www.weixueyuan.net/view/6373.htmlSummarize:A constructor cannot be declared as a virtual function, and a destructor can be declared as a virtual function.After the destructor of the base class is declared as a virtual function, the
Declare the destructor of the polymorphism base class as a virtual function.
Now we want to consider a timer problem. First we create a base class named timekeeper, and then create various derived classes based on it, so that we can use different
1. destructor and virtual destructorIf the destructor of the base class is virtual, The destructor of its derived class are virtual.This will cause: When the derived class destructor, all of its basic class destructor will be called.Otherwise, only
Chapter Review:The 1th chapter of effective C + + makes himself accustomed to c++-reading notesEffective C + + 2nd structure/destructor/assignment operation (1)-Reading notes"Effective C + +" 8th custom new and delete-reading notesArticle 05:
C + + destructor
When an object is created, the system automatically calls the constructor to initialize the work, as well as the system automatically calls a function to clean up when the object is destroyed (for example, the various resources
C + + destructor
The inherited development environment that I use: Visual Studio
How to write a destructor when designing a class.Destructors if we do not write,C + + will help us to automatically synthesize one, that is to say:C + + will
I. Virtual destructor
We know that in order to correctly call the object's destructor, a top-level class with a hierarchy is generally required to define its destructor as a virtual function. When deleting an abstract class pointer, you must use
From: http://www.cnblogs.com/chio/archive/2007/09/10/888260.html
I. Virtual destructor
We know that in order to correctly call the object's destructor, a top-level class with a hierarchy is generally required to define its destructor as a virtual
Can a destructor be a pure virtual function in C + +?It is well known that in the process of implementing polymorphism, the destructor of the base class is generally set virtual so that it delete can be called in a multi- state chain . Then can the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.