How to call overloading functions from the base class (not abstract)?
<p>Class DVD inherits class Media, has one more variable than the base class does.</p>

<p>I declare a pointer:</p>

<pre><code>Media* ptr = new DVD(...);
</code></pre>

<p>I want to print out the content of the DVD, so the following code works as expected:</p>

<pre><code>ptr-&gt;print(cout);
</code></pre>

<p>But using the overloaded &lt;&lt; operator only invokes the base class print() function:</p>

<pre><code>cout &lt;&lt; *ptr &lt;&lt; endl;
</code></pre>

<p>So it prints out only the ID, not with the name of the director.</p>

<p>One way to solve this problem is to modify the overload &lt;&lt; operator a bit to make it accept pointers, so:</p>

<pre><code>cout &lt;&lt; ptr &lt;&lt; endl;
</code></pre>

<p>should work, but somehow I must find the way to make <code>cout &lt;&lt; *ptr &lt;&lt; endl;</code> work as expected.</p>

<p>Any advice?</p>

<p>The thing is I can't make the base class (Media) abstract because I need to call an instance of it in the overloading ostream operator, so a pointer of the base class can not invoke the overloading function of the derived class, which it's pointing to.</p>

<p>Code:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

class Media{
    private:
        int id;
    public:
        Media(int _id) : id(_id) {}
        virtual ~Media();
        virtual void print(ostream &amp;out);
        friend ostream&amp; operator &lt;&lt; (ostream&amp; out, Media aMedia);
};
Media::~Media(){}

class DVD : public Media {
    private:
        string director;
    public:
        DVD(int _id, string _director = "unknown") : Media(_id), director(_director) {}
        ~DVD();
        void print(ostream &amp;out);
};
DVD::~DVD(){}

void Media::print(ostream&amp; out){
    out &lt;&lt; "ID " &lt;&lt; id;
}
void DVD::print(ostream&amp; out){
    out &lt;&lt; "DVD: ";
    Media::print(out);
    out &lt;&lt; " Directed by " &lt;&lt; director;
}
ostream&amp; operator &lt;&lt; (ostream&amp; out, Media aMedia){
    aMedia.print(out);
    return out;
}

int main() { 
    Media *ptr = new DVD(352, "Stephen Spielberg"); 
    ptr-&gt;print(cout); // Prints out: "DVD: ID 352 Directed by Stephen Spielberg". Correct!
    cout &lt;&lt; endl; 
    cout &lt;&lt; *ptr &lt;&lt; endl; //Prints out: "ID 352" Incorrect!
} 
</code></pre>
