How do I register all subclasses of a certain parent to a different class
<p>I am designing an application, where multiple geometric primitive types (all inheriting the base <code>Primitive</code> class) are stored in an object of class <code>Scene</code>.</p>

<p>Instead of having a function in my <code>main()</code> that programmatically creates a scene by constructing the primitives and then calling <code>Scene::add(...)</code>, I'd like to have some sort of configuration file that is read at runtime.<br>
This would save me from having to recompile every time I change something about the scene, and seems like a general good idea (in case someone else that can't program might need to use my program sometime)</p>

<p>I've devised a little scheme that defines the scene through a <code>.ini</code> file like so:</p>

<pre><code>[primitivefoo]
type = sphere
pos = 10 20 30
radius = 5.5

[primitivebar]
type = triangle
vertexA = 10 10 -10
vertexB = ...
...
</code></pre>

<p>You get the idea.</p>

<p>My plan is to have each subclass of <code>Primitive</code> register their own method <code>interpretINI(...)</code> in the class <code>Scene</code>. <code>Scene</code> would need some sort of map that maps <code>string</code>-><code>void* (...)</code>, so that I know which type-string from the <code>.ini</code> file corresponds to which subclass of <code>Primitive</code>.</p>

<p>If this entire approach is bad design, and there is already a much more elegant way to achieve what I want to achieve, I would love to hear it. If not, I would be very grateful if someone could help me realize my design. I'm stuck on how to iterate over all <code>Primitive</code> subclasses to have them register themselves in <code>Scene</code>...</p>
