title: checking type of child when argument is passed by base class pointer
body: <p>I have one base <code>B</code> and its 2 derived (<code>D1</code>, <code>D2</code>) classes that look like this</p>
  
  <pre><code>struct B
  {
     virtual B* DoSomething()=0;
  };
  
  struct D1:public B
  {
     B* DoSomething()
     {
        // D1 does something
        return pD1;
     }
  };
  
  struct D2:public B
  {
     B* DoSomething()
     {
       // D2 does something
       return pD2;
     }
  };
  </code></pre>
  
  <p>and now I have a function </p>
  
  <pre><code>void Init(B*pB)
  {
     if(pB is D1)
     {
        D1* pD1=down_cast(pB);
        pD1-&gt;MethodD1();
     }
     else if(pB is D2)
     {
        D2* pD2=down_cast(pB);
        pD2-&gt;MethodD2();
     }
     else
     {
        //do something else
     }
  }
  </code></pre>
  
  <p>I don't want to check types in <code>Init()</code> method like this but don't know what else I can do.</p>