How do I create classes dynamically?

Ali Çehreli acehreli at yahoo.com
Thu Apr 15 12:48:12 UTC 2021


On 4/14/21 1:38 PM, Mario wrote:

 > Maybe I am just too short in D, but I wanted to find out if it is
 > possible to create classes dynamically.

In D world, "dynamically" means "at run time".

 > Maybe at mixin templates?

Both mixins and templates are compile time features.

 > Normally I would think of a macro first

If we are talking about C (and C++) macros, they are compile time 
features as well.

So, I think you want help from D to generate types, which can happen 
only at compile time with statically-typed languages like D. And yes, D 
is a great language for "generative programming" like that.

 > "I was not written, but still I exist!"

Not possible by this "programming language", which wants a source code 
written, by a human or a machine, to be compiled. Still, anything is 
possible: For example, you can generate source code, dispatch a 
compiler, and load dynamically at run time. :)

Ali



More information about the Digitalmars-d-learn mailing list