Here are 2 classes, a parent and a subclass:
class Model
{
    protected:
    static std::list<char *>   list;
}
class SubModel : public Model
{
    // Should add itself to Model::list...
}
So, here are 2 example classes. I would like to create a generic model in a way every subclass (correctly implemented) would register themselves to the static Model::list. That way, any other subclass is able to identify other "existing" models (and type names).
I've tried many ways, but I have no clue how to populate a static member in many other files only once.
Any idea, if it's possible?
EDIT:
I'm looking for a way to do something like Model::list.push_back("SubModel"); somewhere in each sub model (with the according name of course)
EDIT2:
Apparently, only feasible with all push_back in the same function. What I wanted is to make the subclass automatically register themselves. A workaround would be to create a virtual register which would contain a static bool init(false); and register the class. Then, set to true, if the constructors would return if init is true...
 
     
    