title: Why shouldn't I put everything in header?
body: <p>I'm starting to work with C++ and I come from C and Java. I know that in C is strongly advisable to write variable/types/function declarations in the header and variable/types/function definitions in the source code; so when I started coding in C++ I thought to adhere to the same convention as well.</p>
  
  <p>Unluckly for me, in C++ there are several exceptions to this rule, among the others:</p>
  
  <ul>
  <li>template classes;</li>
  <li>inline functions;</li>
  <li>constexpr functions;</li>
  </ul>
  
  <p>This lead me to some confusion in the files: most of them are headers with <code>*.cpp</code> files containing few medium/big member functions.</p>
  
  <p>So my question is: <strong>assuming to code only with classes, not with plain C, why can't I just put everything in the header and have no cpp files?</strong> (sort of Java style); to clarify: I will mostly have to deal with classes, template classes, at most template functions. </p>
  
  <p>For example in <code>Foo.hpp</code>:</p>
  
  <pre><code>class Foo {
  public:
   foo() {
       //body
   }
   bar() {
       //body
   }
  }
  </code></pre>
  
  <p>instead of having the division between <code>*.hpp</code> and <code>*.cpp</code>:</p>
  
  <pre><code>//file Foo.hpp
  class Foo {
  public:
   foo();
   bar();
  }
  
  //file Foo.cpp
  Foo::foo() {
     //body
  }
  Foo::bar() {
     //body
  }
  </code></pre>
  
  <p>Of course something like static global variables will be put in <code>.*cpp</code>, but for my understanding they are the only thing that is <strong>required to be put in cpps</strong> (and their use is strongly discouraged as well).</p>
  
  <p>Can you please tell me what are the weaknesses of this approach? Being a beginner in C++ I'm sure to have ignore some important factor. In my naive view, there is nothing that requires to be in the cpp files (assuming that I'm coding only with classes of course).</p>
  
  <p>Thanks</p>