c++ base class and derived class constraints
<p>The following question might look like a duplicate but I couldn't find the exact idea anywhere else in the site.</p>

<p>A brief introduction: This question raised as I was trying to understand a little more complexity inheritance combination in my class.</p>

<p>One note before I present the question - I don't look for a sort of "Solution", only wish to discuss with you about the topic and acquire a better thinking.</p>

<p>Suppose you have the following lines:</p>

<pre><code>class C : public B 
{
    public : 
        C (const B&amp; b) : B (b) {}
        B&amp; operator*() {return *this;}
};

int main() {
    A* pA = new B();
    C&amp; c = pA -&gt; doIt();
    *c = *pA;
    c = *pA;
    return 1;
}
</code></pre>

<p>This code isn't full and this is the whole purpose - assume it does complie and extract the constraints in this code.
Still I wouldn't just write a code and ask you to explain any constraint of the top off your head but instead I will add my concreate question:</p>

<p>What constraints do we have for the following line :</p>

<pre><code>C&amp; c = pA -&gt; doIt();
</code></pre>

<p>As far as I understand, the above code has one staring constraint which is the hierarchy order of these class : C is derived of B and B is dervied of A (correct me If I'm wrong..)</p>

<p>I was trying to actually define these classes while keeping the hierarchy I described above, and I couldn't have doIt() to return a type of its derived class C. I can use incomplete type C&amp; in the prototype of an A function but yet I cannot return an object of type C.</p>

<p>Thank you in advance,
SyndicatorBBB</p>
