C++ array of the same class hierarchy
<p>According to my book, if I want to make an array of objects that are not in the same class but in the same class hierarchy, I need to use pointers:</p>

<pre><code>class text
{
public:
    void write(string text);
    void show();
private:
    string texte;
};

void text::write(string text)
{
    texte = text;
}

void text::show()
{
    cout &lt;&lt; texte;
}


class text_with_stars : public text
{
public:
    void show();
};

void text_with_stars::show()
{
    cout &lt;&lt; "*";
    text::show();
    cout &lt;&lt; "*";
}

int main()
{
    text* array[2];
    array[0] = new text;
    array[0]-&gt;write("Hello");
    text_with_stars* pointer = new text_with_stars;
    pointer-&gt;write("Hi");
    array[1] = pointer;
    for (int i=0;i&lt;2;i++)
    {
        array[i]-&gt;show();
    }
    return 0;
}
</code></pre>

<p>But when I do this, the output is "HelloHi" meaning that the second object used the show version that is from text and not from text_with_stars, but I made it exactly the same way that the book described. What Is the problem??</p>

<p>Here is what is written in the book:</p>

<blockquote>
<pre><code> Question* quiz[2];
 quiz[0] = new Question;
 quiz[0]-&gt;set_text("Who was the inventor of C++?");
 quiz[0]-&gt;set_answer("Bjarne Stroustrup");
 ChoiceQuestion* cq_pointer = new ChoiceQuestion;
 cq_pointer-&gt;set_text("In which country was the inventor of C++ born?")
 cq_pointer-&gt;add_choice("Australia",false);
 ...
 quiz[1] = cq_pointer;   
</code></pre>
</blockquote>

<p>The chapter  right next to the one I was reading is about virtual functions and it explains that the system will always use the member functions of Question instead of ChoiceQuestion, looks like I should read more before asking questions on internet!</p>