title: Storing derived class to the vector C++
body: <p>I have problem with storing child class object to the vector. I have parent class</p>
  <pre><code>class IngameObject
  {
  protected:
      bool clickable = false;
  };
  </code></pre>
  <p>I have second class</p>
  <pre><code>class Character : public IngameObject
  {
  protected:
      bool clickable = true;
  };
  </code></pre>
  <p>Now, I am trying to create new instance of Character and stroe it to the vector. I have vector defined as</p>
  <pre><code>std::vector&lt;IngameObject*&gt; objVector;
  </code></pre>
  <p>Code for creating Characters and stroring them is</p>
  <pre><code>for(int i = 0; i &lt; 1; i++)
  {
       int a = i*32;
       Character *c = new Character(this-&gt;holderTextures[&quot;texture&quot;], sf::IntRect(a, a, 32, 32), sf::Vector2f(2*a, 10.f));
       std::cout &lt;&lt; instanceof&lt;Character&gt;(c) &lt;&lt; &quot; TEST&quot; &lt;&lt;std::endl;
       this-&gt;objVector.emplace_back( c );
       std::cout &lt;&lt; instanceof&lt;Character&gt;(this-&gt;objVector.back()) &lt;&lt; &quot; TEST&quot; &lt;&lt;std::endl;
  }
  </code></pre>
  <p>In the first case, instance is Character. After emplace_back to the objVector is type of instance IngameObject and bool clickable is set to false. What I am doing wrong?</p>
  <p>EDIT
  Instanceof is defined as</p>
  <pre><code>template&lt;typename Base, typename T&gt;
  inline bool instanceof(const T*) {
     return std::is_base_of&lt;Base, T&gt;::value;
  }
  </code></pre>