title: Default variables in virtual functions
body: <p>I'm sure there is already a proper answer for this question on StackOverflow but I didn't manage to find it.</p>
  
  <p>I met this example at some c++ test and it was an unexpected behaviour for me.</p>
  
  <pre><code>class A {
  public:
      virtual int foo(int n = 3) {
          return n &lt;&lt; 2;
      }
  };
  
  class B : public A {
  public:
      int foo(int n = 4) {
          return n &lt;&lt; 3;
      }
  };
  
  void main() {
      B b;
      A *a = &amp;b;
      std::cout &lt;&lt; a-&gt;foo() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>I always knew that overwritten <strong>foo</strong> from <strong>B</strong> class would be called in example, but default value for <strong>n</strong> taken from <strong>base</strong> class <strong>foo</strong> was really unexpected.</p>
  
  <p>The same output (24) we'll obtain by replacing <strong>pointer</strong> to B with <strong>reference</strong> to B.</p>
  
  <p><strong>My questions are</strong>:</p>
  
  <ul>
  <li>Why is <strong>n</strong> initialized with <strong>3</strong> instead of <strong>4</strong>?</li>
  <li>Could someone provide some explanation (if it possible, with some <strong>specification</strong> references) for that behaviour?</li>
  </ul>