title: C++ polymorphism and default argument
body: <p>I have these classes:</p>
  
  <pre><code>class Base
  {
      public:
          virtual void foo(int x = 0)
          {
              printf("X = %d", x);
          }
  };
  
  class Derived : public Base
  {
      public:
          virtual void foo(int x = 1)
          {
              printf("X = %d", x);
          }
  };</code></pre>
  
  <p>When I have:</p>
  
  <pre><code>Base* bar = new Derived();
  bar->foo();</code></pre>
  
  <p>My output is "X = 0", even if foo is called from Derived, but when I have:</p>
  
  <pre><code>Derived* bar = new Derived();
  bar->foo();</code></pre>
  
  <p>My output is "X = 1". Is this behavior correct? (To select default parameter value from the declaration type, instead of selecting it from actual object type). Does this break C++ polymorphism? </p>
  
  <p>It can cause many problems if somebody uses virtual functions without specifying the actual function parameter and uses the function's default parameter.</p>