title: C++ inheritance and function overriding
body: <p>In C++, will a member function of a base class be overridden by its derived class function of the same name, <strong>even if its prototype (parameters' count, type and constness)  is different</strong>? I guess this a silly question, since many websites says that the function prototype should be the same for that to happen; but why doesn't the below code compile? It's a very simple case of inheritance, I believe.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  
  class A {};
  class B {};
  
  class X
  {
  public:
      void spray(A&amp;)
      {
          cout &lt;&lt; "Class A" &lt;&lt; endl;
      }
  };
  
  class Y : public X
  {
  public:
      void spray(B&amp;)
      {
          cout &lt;&lt; "Class B" &lt;&lt; endl;
      }
  };
  
  int main()
  {
      A a;
      B b;
      Y y;
  
      y.spray(a);
      y.spray(b);
  
      return 0;
  }
  </code></pre>
  
  <p>GCC throws</p>
  
  <pre><code>error: no matching function for call to `Y::spray(A&amp;)'
  note: candidates are: void Y::spray(B&amp;)
  </code></pre>