title: Cannot modify Derived that was static_pointer_cast from a vector<shared_ptr<Base>>
body: <p>The title describes the situation, but the underlying problem might be something completely different.</p>
  
  <p>I am trying to make a simple ECS game engine. I have a bunch of entities where each one contains a <code>vector&lt;shared_ptr&lt;Component&gt;&gt;</code>. <code>Component</code> is the base class for all the derived components. </p>
  
  <p>During the game loop i have different <code>System</code>s that update entities with certain components. The way I get the correct component for the system is with the following function</p>
  
  <pre><code>        template &lt;typename T&gt; 
          inline T&amp; GetComponent(std::uint32_t type)
          {
              std::shared_ptr&lt;Component&gt; baseComponent = this-&gt;components[this-&gt;typeToIndexMap[type]];
              std::shared_ptr&lt;T&gt; component = std::static_pointer_cast&lt;T&gt;(baseComponent);
              return *(component.get());
          }
  </code></pre>
  
  <p>The issue is that when I try to modify the component in the system  (<code>inputComponent.lastX = 5.f;</code>) it does not work. The next frame the values are the same. I am guessing that there happens some kind of cutoff because i am storing <code>Component</code> but am not sure how to solve this. Any ideas if that is actually the case and how I can solve it ?</p>
  
  <p>Edit : Additional info</p>
  
  <p>Entity holds components in a <code>vector&lt;shared_ptr&lt;Component&gt;&gt;</code></p>
  
  <p>Adding a Component</p>
  
  <pre><code>void Entity::AddComponent(std::shared_ptr&lt;Component&gt; component)
  {
      this-&gt;components.push_back(component);
      this-&gt;componentBitset = this-&gt;componentBitset | component-&gt;GetComponentType();
      this-&gt;typeToIndexMap[component-&gt;GetComponentType()] = this-&gt;components.size() - 1;
  }
  </code></pre>
  
  <p>Component Creation</p>
  
  <pre><code>std::shared_ptr&lt;InputComponent&gt; inputComponent = std::make_shared&lt;InputComponent&gt;(InputComponent());
  entity-&gt;AddComponent(inputComponent);
  </code></pre>
  
  <p><strong>Component Structure</strong></p>
  
  <pre><code>class Component
  {
  public:
      // Constructor / Destructor
      Component(std::uint32_t type);
      ~Component();
      std::uint32_t GetComponentType();
  
  private:
      std::uint32_t type;
  };
  </code></pre>
  
  <p>Input Component</p>
  
  <pre><code>class InputComponent : public Component
  {
      public:
          InputComponent();
          ~InputComponent();
  
          double lastX;
          double lastY;
  };
  </code></pre>
  
  <p>Finally we have the system</p>
  
  <pre><code>void InputSystem::Update(GLFWwindow* window, std::vector&lt;std::shared_ptr&lt;Entity&gt;&gt;&amp; entities)
  {
      for (int i = 0; i &lt; entities.size(); i++)
      {
          if (entities[i]-&gt;IsEligibleForSystem(this-&gt;primaryBitset))
          {
              InputComponent component = entities[i]-&gt;GetComponent&lt;InputComponent&gt;(ComponentType::Input);
              double x, y;
              glfwGetCursorPos(window, &amp;x, &amp;y);
              // some other things are happening here
              component.lastX = x;
              component.lastY = y;
          }
      }
  }
  </code></pre>