Dynamic binding for virtual functions
<pre><code>class base {
public:
    virtual void foo()
    {
         cout &lt;&lt; "Base class virutal function " &lt;&lt; endl;
     }
}

class Derived : public base {
public:
    void foo()
     {
          cout &lt;&lt; "Derived class virtual function " &lt;&lt; endl;


int main()
{
    Base b, *ptr;
    Derived d;

    ptr = &amp;b;
    ptr-&gt;foo();
    ptr = &amp;d;
    ptr-&gt;foo();
}
</code></pre>

<p>Hi,
I have a doubt regarding dymnamic binding here. since compiler knows that when b.foo() is there it can use base virtual fumction. and when d.foo() is present it can use derived version of foo. I mean compiler has every bit of info during compile time but still literature says that which function will be used is decided at run time. </p>
