C++ Type casting base object to derived object
<p>So i have a dynamically allocated array of base class. I've stored a few objects of its derived class inside the array.</p>

<p>The student (base) class and its derived classes all have a getInfo() function, obviously the derived classes have overrided that base getInfo(). The goal is to used the getinfo function from the base class, then type class the two objects of the derived class, back into the derived class and use the overrided getinfo().</p>

<p>Everything up to "break" works perfect. It's figuring out how to type cast the objects back into the derived classes that's killing me. </p>

<p>I've identified a few possible issues:</p>

<p>1) I didnt dynamically allocate correctly. Very possible because I hate pointers and very much suck at them.</p>

<p>2) I have no idea what Im doing with regard to actually type casting.</p>

<p>A few things of note:
1) The base class getinfo is not virtual</p>

<p>2) I am not allowed to modify the base class.</p>

<p>So, saviors of confusing code. What say you? Can you help this poor student out?</p>

<p>EDIT!!!</p>

<p>Updated code, now getting "Static_cast from Student ** to Gradstudent * is not allowed"</p>

<pre><code>#include &lt;iostream&gt;

#include "GradStudent.h"
#include "UndergradStudent.h"

int main()
{
    int arraySize = 3;
    Student* classRoom[arraySize];

    GradStudent gst1("Ta", "Da", 4444, 'A', "Death");
    cout &lt;&lt; gst1;

    UndergradStudent ust1("Bluh", "Bluh", 2222, 1);
    cout &lt;&lt; ust1;

    Student bst1( "Blah", "Blah", 1111 );

    classRoom[0] = &amp;bst1;
    classRoom[1] = &amp;gst1;
    classRoom[2] = &amp;ust1;



    for (int x = 0; x &lt; arraySize; x++)
    {
        cout &lt;&lt; classRoom[x]-&gt;getInfo();
        cout &lt;&lt; endl;
    }

    cout &lt;&lt; "TEST" &lt;&lt; endl;

    GradStudent* gStudent =  static_cast&lt;GradStudent*&gt;(&amp;classRoom[2]);
    cout &lt;&lt; gStudent-&gt;getInfo();



    return 0;
}
</code></pre>
