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
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
C + + static correlation and dynamic Association, C + + is how to achieve polymorphismIn real life, there are many examples of polymorphism. Let's analyze how people deal with polymorphism. For example, when a freshman is enrolled in a university,
Constructor:
C ++ provides constructor to process object initialization. It is automatically executed when an object is created. The name of the constructor must be the same as the class name. It does not have any type or return any value. 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
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 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
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
Another feature of the type that requires the virtual destructor is that the type has pointer members or reference members. If there are pointer and reference members, this type usually requires destructor and copy operations.
Generally, a
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.