In C + +,
You cannot declare a fictional function, but you can declare a virtual destructor. Polymorphism means that different objects have different behavioral characteristics to the same message. Virtual functions are the basis of run-time
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
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
C + + clearly states: when the derived class object is deleted by a base class pointer, and the base class takes a non-virtual destructor, the result is undefined-- The actual execution usually occurs when the derived component of the object is not
Li Jianzhong (Nanjing University of Posts and Telecommunications (Cornyfield@263.net)
Constructor
The constructor initializes the member variables (fields) in the class. The C # class has two constructor types: instance constructor and static
I have been talking about it for a long time. msdn also has a very detailed description, but it does not seem very systematic. I have also done some analysis, but I did not forget to summarize it. This time, I will sort out some information
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
What kind of situations require a virtual destructor? Classes need to control what happens when their objects perform a series of operations, including creating (objects), copying, moving, assigning, and destroying. In an inheritance system, if a
1. Why do I need to define a virtual destructor?
If oneClass with the virtual function, it needs a virtual destructorFor the following reasons:1) if a class has a virtual function, it is often used as a base class;2) if it is a base class, Its
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
1. Fictitious Function Definition
A destructor is a special user-defined member function. When an object of this class leaves its domain or delete expression and is applied to the pointer of an object of this class, the Destructor is
Inherited constructor destructor
Call of constructor and destructor in class inheritance
Currently, there are three classes. The class definition is as follows:
Class ca{Public:CA () {cout ~ CA () {cout
};
Class CB: public CA{Public:CB () {cout
Article 2 destructor
The Destructor are rarely used in C #, so many people have forgotten it. Although it is of little use, it is useless to study it.
I. Features of destructor:
Destructor can only exist in classes, but not in structures.
1. Why C + + does not like destructors throw exceptions
C + + does not prevent the destructor from appearing abnormally, but it certainly does not encourage this. This is for a reason, consider the following code:
1 class Widget {
2
3 public:
4
In each class, there are constructors, destructors, assignment operators. These functions are the fundamental function of a class that controls the creation and initialization of objects, the cleanup of objects when they die, and the assignment of
When you create an object, the system automatically invokes the constructor for initialization, and the system automatically calls a function to clean up when the object is destroyed, such as releasing allocated memory, closing open files, and so on,
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
Base * pb; inherit C; // inherit is the Pb that inherits the base = & C; Delete Pb; the object's destructor must be called. If the base class destructor are not virtual, the destructor of the corresponding class is called according to 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.