Discover calling virtual function from constructor, include the articles, news, trends, analysis and practical advice about calling virtual function from constructor on alibabacloud.com
Http://anwj336.blog.163.com/blog/static/8941520920106791516915/
1. constructor to avoid calling virtual functions
Although calling a virtual member function in constructor is not a very common technique, studying it can deepen the understanding of
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.
In C ++, constructor is a special function called when the component object is called. Its purpose is to initialize the object, so that the object can be in a reasonable State before it is used. However, the design of constructor functions is not
C ++ constructor & copy constructor & constructor of derived classes & constructor of virtual inheritanceConstructor is a special method. It is mainly used to initialize an object when an object is created, that is, assigning an initial value to the
Why can't constructors be virtual functions and basic class destructor?I. Why cannot constructors be virtual functions?1. From the perspective of storage space, virtual functions correspond to a pointer to the vtable virtual function table. We all
See stroustrup's answer (http://www.research.att.com /~ BS/bs_faq2.html # vcall)
Although calling a virtual member function in constructor is not a very common technique, studying it can deepen the understanding of the virtual function mechanism
on the unreasonable design of C + + construction function
Author: Zhang
In C + +, a constructor is a special function that is invoked at the time of the Component object to initialize the object so that the object can be in a reasonable state before
C ++ constructor & amp; copy constructor & amp; constructor of the derived class & amp; virtual inherited Constructor
Constructor is a special method. It is mainly used to initialize an object when an object is created, that is, assigning an initial
C ++ virtual functions and virtual function table Parsing1. Definition of virtual functions
A virtual function must be a non-static member function (and a non-constructor) of the class. Its access permission can be defined as private or proteceted,
The function of virtual function in C + + is mainly to realize the mechanism of polymorphism. About polymorphism, in short, is to use the pointer of the parent type to an instance of its subclass, and then call the member function of the actual
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.