LeeLin blog
(1) When the base class does not have its own constructor, the default bar of the derived class uses the constructor of the base class.(2) When the base class has a self-compiled constructor, you must add a constructor without parameters
(1) When the base class does not have its own constructor, the default bar of the derived class uses the constructor of the base class.(2) When the base class has a self-compiled constructor, you must add a constructor without parameters to the base
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
Because a derived class is inherited from a base class, it contains some members of the base class. Therefore, when writing the constructor and replication control function of the derived class, you must consider the impact of the base class.
First,
1. member functions that cannot be automatically inherited
Constructor (including copy constructor)
Destructor= Operator
Ii. Inheritance and constructor
The constructor of the base class is not inherited. You must declare your own constructor In
C + + base class and derived class conversionsIn public inheritance, in private inheritance and protection inheritance, only public inheritance can preserve the characteristics of the base class, it retains all members of the base class except
Note: the scope of this article is limited to the execution of constructors and does not involve the design of classes.
1. Call Sequence of Constructor
When instantiating a class, the System. Object is always called first, and then the class
An understanding of the basic class constructor called by a derived class in C.C # class default constructor in this document refers to the system default non-argument constructor without compiling Constructor
1. When the base class does not write
4.5 Assignment compatibility relationship between a base class and a derived class objectUnder certain conditions, type conversions can be made between different types of data, such as the ability to assign integer data to a double type
I. Purpose of introducing inheritance
1. code reuse
The Inheritance and derivation mechanisms of classes enable programmers to get new classes by adding a small amount of code or modifying a small amount of code on the basis of existing classes
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.