title: What exactly are conditions for dynamic binding?
body: <pre><code>class Foo
  {
  public:
      void f() {}
  
      virtual void g() {}
  };
  
  class Bar : public Foo
  {
  public:
  
      void f() {}
  
      virtual void g() {}
  };
  
  int main()
  {
      Foo foo;
      Bar bar;
  
      Foo *a = &amp;bar;
      Bar *b = &amp;bar;
  
      // case #1
      foo.f();
      foo.g();
  
      // case #2
      bar.f();
      bar.g();
  
      // case #3
      a-&gt;f();
      a-&gt;g();
  
      // case #4
      b-&gt;f();
      b-&gt;g();
  }
  </code></pre>
  
  <p>In first and second case as far as I can tell compiler should already know what types are, so I guess there be no dynamic binding.</p>
  
  <p>But I'm not sure about the third and fourth cases. In third case, in my opinion compiler can know the types if it tries a little hard to guess where the pointer is pointing at. So there may or may not be dynamic binding.</p>
  
  <p>In forth case, would a derived class pointer to derived class object still have to involve dynamic binding?</p>