Use static_cast to dynamic polymorphism : <p>I used a static_cast to polymorphism.
I read that I should use dynamic_cast, but I can't get why.
Code works in both way (with static and dynamic cast).</p>

<p>Could anybody show me an example with necessary dynamic_cast operator? </p>

<pre><code>class Base
{
    public:
    virtual void foo() = 0;
};

class D1 : public Base
{
    public:
    void foo()
    {
        std::cout &lt;&lt; "D1()";   
    }
};

class D2 : public Base
{
    public:
    void foo()
    {
        std::cout &lt;&lt; "D2()";   
    }
};


int main()
{
    srand( time( NULL ) );
    int r = std::rand()%2;

    Base* b_ptr;

    if(r == 0)
    {
        b_ptr = static_cast&lt;Base*&gt;(new D1);    
    }
    else
    {
          b_ptr = static_cast&lt;Base*&gt;(new D2);   
    }

    b_ptr-&gt;foo();
}
</code></pre>
