Downcasting using reinterpret_cast in C++
<p>I'm just trying to understand the down casting in more details, I understand that it is not advisable as it leads to undefined run time behavior. When do we really need to use down casting? </p>

<p>Also consider the coding snippet and the dynamic_cast returns for the down casting but when I use reinterpret_cast it prints out the derived class function rightly, how? The object slicing will take in place only when assigning objects by value but not by reference or pointers? </p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

class base
{
    public:
    void func1()
    {
        std::cout&lt;&lt;"\n Base Function"&lt;&lt;std::endl;
    }
    virtual ~base(){cout&lt;&lt;"\n Base Destructor"&lt;&lt;endl;}
};

class derived:public base
{
    public:
    void func2()
    {
        std::cout&lt;&lt;"\n Derived Function"&lt;&lt;std::endl;
    }
};

int main() 
{

    base *ptr = dynamic_cast&lt;base*&gt;(new derived); // Up casting
    if (ptr)
    {
        ptr-&gt;func1();
    }
    else
    {
        cout&lt;&lt;"\n casting failed"&lt;&lt;endl;
    }

    derived *ptr1 = dynamic_cast&lt;derived*&gt;(new base); // Down casting
    if (ptr1)
    {
        ptr1-&gt;func2();
    }
    else
    {
        cout&lt;&lt;"\n ptr1 casting failed"&lt;&lt;endl;
    }

    return 0;
}
</code></pre>