title: default parameters in .h and .cpp files
body: <p><strong>COMPILER:</strong>  <em>g++ 4.7.2</em></p>
  
  <p>Ok. So I am confused about default parameters in <code>.h</code> and <code>.cpp</code> files. It is mentioned in many places( including this site) that default parameters can be added only in .h files and not in .cpp files. 
  However, this code proves it wrong:</p>
  
  <p><strong>test1.h</strong></p>
  
  <pre><code>#pragma once
  
  #include &lt;iostream&gt;
  using namespace std;
  
  class Class{
  public:
      Class(int, int, int=1);
  };
  </code></pre>
  
  <p><strong>test1.cpp</strong></p>
  
  <pre><code>#include "test1.h"
  
  Class::Class(int a, int b=2, int c)
  {
      cout&lt;&lt;a&lt;&lt;" "&lt;&lt;b&lt;&lt;" "&lt;&lt;c&lt;&lt;endl;
  }
  
  int main()
  {
      Class a(1);
      return 0;
  }
  </code></pre>
  
  <p>Now, according to what I have tested, default parameters can be added to <code>.cpp</code> files. However, the following restrictions hold:</p>
  
  <ol>
  <li><p>The default parameters present in <code>.cpp</code> and <code>.h</code> file should not
  overlap. i.e. <code>Class(a, b, c=1)</code> (in .h file) and
  <code>Class::Class(a,b,c=2)</code>( in .cpp file) is invalid.</p>
  
  <p>It is a well known rule that once default parameters have been
  added, all the variables declared after that must also contain
  default values. Lets call this the <em>defpara</em> rule. Now,</p></li>
  <li><p>The variables stated in the function declaration( <code>.h</code> file) should
  obey the <em>defpara</em> rule i.e. <code>Class(a, b=2, c)</code> (in .h file)  is
  invalid irrespective of what's declared in .cpp file.</p></li>
  <li><p>If one considers the variables having default values (as an
  intersection of default values in <code>.h</code> and <code>.cpp</code> files), it would
  follow the <em>defpara</em> rule. i.e. <code>Class(a, b, c=1)</code> (in .h file) and
  <code>Class::Class(a,b=2,c)</code>( in <code>.cpp</code> file) is valid. But <code>Class(a, b,
  c=1)</code> (in .h file) and <code>Class::Class(a=2,b,c)</code>( in <code>.cpp</code> file) is
  invalid.</p></li>
  </ol>
  
  <p>So....I am right, wrong???</p>