C + + Exchange Group: 302558294 (Welcome to join)
Original Address: http://blog.csdn.net/jiadebin890724/article/details/7951461#comments, thank the original author to share
first, be clear:
1. Each destructor (without virtual) is responsible
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
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
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.
Pure virtual member functions are generally not defined. They are declared in the abstract class and then implemented in the derived class. For example:
Class file // an
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
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:
Destructor usage:1. Each destructor (without virtual) is only responsible for clearing its own members. 2. There may be a base class pointer pointing to the case where it is indeed a member of a derived class.For the second case:Correct execution:
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
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
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.