Introduction
The aim of this article is to explain the upcasting. Before going through this article I expect people have some preliminary idea about inheritance mechanism.
Background
The term upcasting comes from the class inheritance diagram. In the class inheritance diagram we generally draw the base class in the top and the derived class grows downward.
Code:
--------------------
| Base |
--------------------
|
--------------------
| Derived |
--------------------
The code
Code: Cpp
Code:
#include <iostream>
using namespace std;
class Base
{
public:
void Information()
{
cout << "We are in Base Information" <<endl;
}
};
class Derived : public Base
{
void Information()
{
cout << "We are in Derived Information" <<endl;
}
};
void Generic(Base &base)
{
base.Information();
}
int main() {
Derived derived;
Generic(derived); /// Upcasting
return 0;
}

