c++: Calling base class virtual function using base class pointer of derived class instance : <p>I have three classes: I have access to the only base class pointer, but this pointer is actually a derived class object. I want to use this base pointer to call the base class virtual function.</p>

<pre><code>    class A
    {
        public:
        virtual void print() = 0;
    };

    class B: public A
    {
       public:
        virtual void print() override { cout &lt;&lt;"I am B\n"; }
    };

    class C: public B
    {
        public:
        virtual void print() override { cout &lt;&lt;"I am C\n"; }
    };

    int main()
    {
        cout&lt;&lt;"Hello World\n";

        A *a = new C();
        a-&gt;print(); // prints "I am C"

        //use pointer 'a' to print "I am B"

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