📜  c++代码示例中的向上转换

📅  最后修改于: 2022-03-11 14:44:48.042000             🧑  作者: Mango

代码示例1
Upcasting and downcasting are an important part of C++. Upcasting and downcasting give a possibility to build complicated programs with a simple syntax. It can be achieved by using Polymorphism.

C++ allows that a derived class pointer (or reference) to be treated as a base class pointer. This is upcasting.

Downcasting is an opposite process, which consists of converting base class pointer (or reference) to derived class pointer.

C++ Upcasting and Downcasting should not be understood as a simple casting of different data types. It can lead to great confusion.

In this topic, we will use the following hierarchy of classes: