title: C++ Base Class Function Overloading in a Subclass
body: <p>Given the following...</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class BaseClass {
  public:
      void Func(float f) {
          cout &lt;&lt; "BaseClass:Func() called!";
      }
  };
  
  class SubClass : public BaseClass {
  };
  
  int main() {
      SubClass sub;
      sub.Func(1.1f);
      return 0;
  }
  </code></pre>
  
  <p>This runs pretty much as one would expect, resulting in the following output...</p>
  
  <blockquote>
    <p>BaseClass:Func() called!</p>
  </blockquote>
  
  <p>However, if I add the following function to SubClass...</p>
  
  <pre><code>class SubClass : public BaseClass {
  public:
      void Func(int i) {                        // accepts an int, not a float!
          cout &lt;&lt; "SubClass::Func() called!";
      }
  };
  </code></pre>
  
  <p>Like any other overload, I would expect the SubClass function to be called if I supply an int as my argument, and BaseClass's if I supply a float.  However, if I run the program as-is (ie. with the float), this is not the case...</p>
  
  <blockquote>
    <p>SubClass::Func() called!</p>
  </blockquote>
  
  <p>Instead of what I was expecting, the float I provided is cast to an integer, and the SubClass function is called.  It seems SubClass's function effectively shadows BaseClass's function, even though its signature differs.</p>
  
  <p>Can someone shed some light on this?  Is there a way to call the BaseClass function via a SubClass instance without having to cast it?</p>
  
  <p>Thanks!</p>