title: C++ function overloading and dynamic binding compile problem
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/2068088/c-method-only-visible-when-object-cast-to-base-class">C++ method only visible when object cast to base class?!</a><br>
    <a href="https://stackoverflow.com/questions/1628768/why-does-an-overridden-function-in-the-derived-class-hide-other-overloads-of-the">Why does an overridden function in the derived class hide other overloads of the base class?</a>  </p>
  </blockquote>
  
  
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A
  {
  public:
      virtual void foo(void) const { cout &lt;&lt; "A::foo(void)" &lt;&lt; endl; }
      virtual void foo(int i) const { cout &lt;&lt; i &lt;&lt; endl; }
      virtual ~A() {}
  };
  
  class B : public A
  {
  public:
      void foo(int i) const { this-&gt;foo(); cout &lt;&lt; i &lt;&lt; endl; }
  };
  
  class C : public B
  {
  public:
      void foo(void) const { cout &lt;&lt; "C::foo(void)" &lt;&lt; endl; }
  };
  
  
  int main(int argc, char ** argv)
  {
      C test;
  
      test.foo(45);
  
      return 0;
  }
  </code></pre>
  
  <p>The above code does not compile with:</p>
  
  <pre><code>$&gt;g++ test.cpp -o test.exe
  test.cpp: In member function 'virtual void B::foo(int) const':
  test.cpp:17: error: no matching function for call to 'B::foo() const'
  test.cpp:17: note: candidates are: virtual void B::foo(int) const
  test.cpp: In function 'int main(int, char**)':
  test.cpp:31: error: no matching function for call to 'C::foo(int)'
  test.cpp:23: note: candidates are: virtual void C::foo() const
  </code></pre>
  
  <p>It compiles if method "foo(void)" is changed to "goo(void)". Why is this so? Is it possible  to compile the code without changing the method name of "foo(void)"?</p>
  
  <p>Thanks.</p>