title: C++ dynamic binding with overloading
body: <p>Suppose:</p>
  
  <pre><code>struct A {
      virtual int foo(const A&amp; a) const { return 1; }
  };
  
  struct B : A {
      virtual int foo(const A&amp; a) const { return 2; }
      virtual int foo(const B&amp; b) const { return 3; }
  };
  
  void testOverloadingBinding(const A&amp; a,const B&amp; b) {
      cout &lt;&lt; a.foo(b);
  }
  
  int main() {
      testOverloadingBinding(B(),B());
  }
  </code></pre>
  
  <p>It prints 2. I would assume it prints 3 since <code>this</code> binding is dynamic, and as far as I know overloading has static binding.
  Can anyone please explain how the compiler decides which function to invoke here?</p>