title: Multiple definition C++
body: <p>Ok, this has been covered already, for example here: <a href="https://stackoverflow.com/questions/10722173/static-array-class-variable-multiple-definition-c">static array class variable &quot;multiple definition&quot; C++</a></p>
  
  <p>But I am missing some details here.</p>
  
  <p>I have got the following classes:
  Foo.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Model.h"
  
      int main(int argc, char** argv){
          std::cout &lt;&lt; "hello" &lt;&lt; std::endl;
          return 0;
      }
  </code></pre>
  
  <p>Model.h</p>
  
  <pre><code>#ifndef MODEL_H
  #define MODEL_H
  
  #include &lt;string&gt;
  #include "md2Loader.h"
  
  class Model{
      public:
      Model();
      Model(const std::string&amp; model_file);
  
      private:
      md2_header_t header;
      modelData_t model;
  };
  
  #endif
  </code></pre>
  
  <p>Model.cpp</p>
  
  <pre><code>#include "Model.h"
  #include "md2Loader.h"
  
  Model::Model(){}
  
  Model::Model(const std::string&amp; model_file){
      model = md2Loader::load_model(model_file);
  }
  </code></pre>
  
  <p>and md2Loader.h</p>
  
  <pre><code>#ifndef MD2LOADER_H
  #define MD2LOADER_H
  
  struct modelData_t{
      int numVertices;
      int numTextures;
      // etc
  };
  
  struct md2_header_t {
      std::string version;
  };
  
  class md2Loader{
  public:
      md2Loader(){};
      static modelData_t load_model(const std::string&amp; model_file);
  };
  
  modelData_t md2Loader::load_model(const std::string&amp; model_file){
      modelData_t result;
      result.numVertices = 1000;
      result.numTextures = 10;
  
      return result;
  }
  
  
  #endif
  </code></pre>
  
  <p>The linker complains of multiple definitions. But I am not quite sure, why. Do the #ifndef, #define preprocessor directives not help? I kind of get it that md2Loader.h get included to both Model.cpp and Model.h. When I do the implementation in Model.h and leave Model.cpp away it will compile and link just fine. I thought, that the directives for the preprocessor prevent that from happening, but obviously I am missing something there.</p>