C++ store any child struct/class in array?
<p>In C++ I have a series of structures defined...</p>

<pre><code>struct Component {};
struct SceneGraphNode : Component {};
struct Renderable : Component {};
struct Health : Component {};
</code></pre>

<p>These could easily be classes, I've been told that there is very little difference in C++.</p>

<p>In Java it is possible to declare an array of type <code>Component</code> and put any class that extends from (inherits) <code>Component</code> into it. Java considers them all components and since everything uses smart pointers, Java's "array" is really just a list of smart-pointers which are all the same size. </p>

<p>However I understand that Java handles arrays significantly different from C++. When I checked the size of each of these structs I got the following. </p>

<pre><code>Component                   // 4
SceneGraphNode : Component  // 8
Renderable : Component      // 8
Health : Component          // 20
</code></pre>

<p>Which isn't suprising. Now when I create an array of Components, the size of the blocks are obviously going to be 4 (bytes) which won't hold any of the other structures.</p>

<p>So my question is, how can I store a loose list of <code>Components</code> (IE a list that can store any class / struct that inherits from Component)? In Java this is mind-numbingly simple to do. Surely there must be an easy way in C++ to do it. </p>
