Each derived class object contains a base class, which means that the operation can be performed on the derived class object like the base class object. Because the derived class object is also a base class object, there is an automatic conversion from the reference of the derived class type to the base class type, that is, you can convert the reference of the derived class object to the reference of the base class object, the pointer is similar.
A base class object can exist as an independent object or a part of a derived class object. Therefore, a base class object may or may not be part of a derived class object, the result is not automatically converted from the base class reference to the reference of the derived class, as is the pointer.
Object conversion is more complex than reference or pointer conversion. Although objects of the derived type can be used to initialize or assign values to objects of the base class type, there is no direct conversion from objects of the derived class to objects of the base class type.
You can directly use the object of the derived class to assign values to or initialize the base class object.
You can directly use the reference or object of a derived class to assign values or initialize the base class reference.
Conversion by reference is different from conversion object
Pass the derived class object to the function that you want to accept the base class reference. The reference is directly bound to the object, and the object itself is not copied.
Pass the derived class object to the function that wants to accept the base class object, and the shape parameter type is fixed ----- when compiling and running, the shape parameter is a base class object. If the real parameter is a derived class object, the base class of the object in the derived class is copied to the form parameter.
Accessibility of conversion from a derived class to a base class
Like an inherited Member, conversion from a derived class to accumulation may or may not be accessible. Whether the conversion is accessible depends on the access label specified in the derived list of the derived class. If it is a public inheritance, it is acceptable; otherwise it cannot be converted.