how to use cast in c++
<p>I have a question related to the static_cast in c++. </p>

<p>I have :</p>

<ul>
<li>a class B and its derived class D</li>
<li>a class BData and its derived class DData</li>
</ul>

<p>Here is the code:</p>

<pre><code>class B 
{
  public:
    B(BData * pb)
    {
    }
};

class D : public B 
{
  public:
    D(DData * pd) : B( static_cast&lt;BData*&gt;(pd))
    {
    }
};
</code></pre>

<p>The compilation always gives an error:</p>

<pre><code>error C2440: 'static_cast' : cannot convert from 'DData *' to 'BData *',
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
</code></pre>

<p>Does anybody know why?</p>
