title: Global std::vector is not retaining data
body: <p>I have a header...</p>
  
  <p><em>Components.h</em></p>
  
  <pre><code>namespace ComponentManager
  {
    void InitializeComponents(std::size_t numComponents);
    void AddComponent(const Component&amp; c, std::size_t position);
    std::vector&lt;Component&gt; GetComponents();
  }
  </code></pre>
  
  <p>... and the implementation:</p>
  
  <p><em>Components.cpp</em></p>
  
  <pre><code>#include "Components.h"
  
  std::vector&lt;ComponentManager::Component&gt; components;
  
  void ComponentManager::InitializeComponents(std::size_t numComponents)
  {
    components.resize(numComponents, Component());
  }
  
  void ComponentManager::AddComponent(const Component&amp; c, std::size_t pos)
  {
    components[pos] = c;
  }
  
  std::vector&lt;ComponentManager::Component&gt; ComponentManager::GetComponents()
  {
    return components;
  }
  </code></pre>
  
  <p>In <em>main.cpp</em>, I make sure to initialize the components vector, and I add several components. Upon debugging each AddComponent(...) call, I see that the components are actually stored in the vector. However, when I call GetComponents(), the returned vector is different, as if the components were never stored.</p>
  
  <p>What am I missing?</p>
  
  <p>EDIT: Adding main.cpp (inside main() function)</p>
  
  <pre><code>//Inside EntityManager::Initialize(), I call ComponentManager::InitializeComponents()
  EntityManager::Initialize(5000);
  for (unsigned int i = 0; i &lt; 10; ++i)
  {
      uint16_t handle = EntityManager::CreatePlayer(static_cast&lt;float&gt;(i), 50.0f * i);
      //Inside EntityManager::AddComponent, I call ComponentManager::AddComponent(..)
      EntityManager::AddComponent(handle, ComponentManager::POSITION_COMPONENT | ComponentManager::RENDERABLE_COMPONENT);
  }
  auto components = ComponentManager::GetComponents(); //this vector does not contain the elements that were added.
  </code></pre>