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:
Code Example |
---|
Cpp :: size of array |
Cpp :: how to find 2d vector length cpp |
Cpp :: how to split a string in c++ |
Cpp :: reverse function in cpp string |
Cpp :: priority queue c++ |
Cpp :: declare nullptr c++ |
Cpp :: how to initialize array with new in c++ |
Cpp :: C++ Vector Iterator Syntax |
Cpp :: break in c++ |
Cpp :: back() in c++ |
Cpp :: c++ string size |
Cpp :: find duplicate from an array c++ |
Cpp :: overload of << c++ |
Cpp :: reverse level order traversal |
Cpp :: 3d projection onto 2d plane algorithm |
Cpp :: print vector c++ |
Cpp :: how to write hello world in c++ |
Cpp :: sleep in c++ |
Cpp :: c++ print out workds |
Cpp :: what is g++ and gcc |
Cpp :: Reverse words in a given string solution in c++ |
Cpp :: c++ random generator |
Cpp :: std::copy C ++ |
Cpp :: cpp ifdef |
Cpp :: c++ pointers and functions |
Cpp :: C++ Integer Input/Output |
Cpp :: number of nodes of bst cpp |
Cpp :: double array c++ |
Cpp :: c++ program to convert celsius to kelvin |
Cpp :: c++ sizeof |