C++ - upcasting and downcasting
<p>In my example:</p>

<p>At upcasting, shouldn't the second <code>d.print()</code> call print "base"?</p>

<p>Isn't it "d" derived object upcasted to a base class object?</p>

<p>And at downcasting, what advantages does it have?</p>

<p>Could you explain upcast and downcast in a practical way?</p>

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

class Base {
public:
    void print() { cout &lt;&lt; "base" &lt;&lt; endl; }
};

class Derived :public Base{
public:
    void print() { cout &lt;&lt; "derived" &lt;&lt; endl; }

};

void main()
{
    // Upcasting
    Base *pBase;
    Derived d;
    d.print();
    pBase = &amp;d;
    d.print();

    // Downcasting
    Derived *pDerived;
    Base *b;
    pDerived = (Derived*)b;
}
</code></pre>