getting all children classes in program

Ondra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 3 07:00:52 PST 2015


>
> I'm not sure if there's a way around that other than to add 
> some code in the class to register itself. You could use a 
> static constructor that adds itself to a list.
>
> Or, to give each class a shared ID, you could add a static 
> member which returns some variation of its typeinfo. In fact, 
> typeid(any_class) returns a unique identifier for each class 
> (an instance of TypeInfo), maybe you can use it directly.

Hi Adam,

static this is probably way to go, I wanted to avoid this 
solution because if it leads to copy-pasting code to every child.

I need to have IDs small like 8bits, co I probably can't use 
typeid...

Thank you for answer. Knowing that someting cannot be done is 
better than spend on this another few hour.

Great book btw.

Ondra


More information about the Digitalmars-d-learn mailing list