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
The theoretical premise of virtual destructor isAfter executing the destructor of the subclass, the fictitious function of the parent class is bound to be executed.Then when you use Delete to release a subclass object that is instantiated by a
First, the article for the reasonNow writing a project requires a multi-tree storage structure, but at some point I need to destroy the tree, which means that if I create a new tree object, I would probably want to end the declaration cycle of this
C ++ shows the traps for calling destructor and function call trapsI. Reasons for the article
I am writing a project and need to use the multi-tree storage structure. But at some point, I need to destroy this tree, which means that if I create a new
Document directory
The constructor cannot be declared as a virtual function. The Destructor can be declared as a virtual function, and sometimes it must be declared as a virtual function.
The constructor cannot be declared as a virtual function.
Copyright NOTICE: Welcome Reprint, note The source is good! If you do not like please leave a message to explain why again step on Oh, thank you, I can also know the reason, continuous progress!!Directory (?) [+]First, the article for the reasonNow
Polymorphism is a basic attribute of object-oriented, including static polymorphism (compile phase) and dynamic polymorphism (runtime phase). Static polymorphism mainly refers to the polymorphism of different function parameters, which is a
From the syntax above, it is possible for destructors to throw exceptions, and C + + does not prevent destructors from throwing exceptions, but C + + does not recommend this practice, and it is dangerous to throw exceptions from
C ++ inherits the calling sequence and virtual destructor of the destructor in the destructor.
First, let's talk about the constructor. We all know that the constructor can call member variables, and the Child class in inheritance is to turn 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.