getting all children classes in program

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 3 06:37:52 PST 2015


On Saturday, 3 January 2015 at 14:28:07 UTC, Ondra wrote:
> class C(T): B {} // missing in ModuleInfo

The reason is that's technically not a class and doesn't exist at 
runtime, it is just a template for one (you can't new that, you'd 
have to new C!some_actual_type). If you were to add a

class D : C!int {}

then you'd see class D shows up and has a parent of C!int... 
however, you're right, C!int doesn't want to show up at all, even 
if I instantiate it.

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.


More information about the Digitalmars-d-learn mailing list