How do I create classes dynamically?
Imperatorn
johan_forsberg_86 at hotmail.com
Thu Apr 15 17:48:02 UTC 2021
On Thursday, 15 April 2021 at 16:39:30 UTC, Kagamin wrote:
> On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote:
>> Maybe I am just too short in D, but I wanted to find out if it
>> is possible to create classes dynamically. My problem is, I
>> just don't know where to start reading. Maybe at mixin
>> templates?
>>
>> CreateClassWithName!("MyDynamicClassName");
>>
>> should create the following class to work with dynamically:
>>
>> class MyDynamicClassName {
>> this() { writeln("I was not written, but still I exist!");
>> }
>> }
>>
>> So that I in the end by means of
>>
>> MyDynamicClassName cls = new MyDynamicClassName;
>
> String mixins is D replacement of macros for code generation.
> Works like this:
> ```d
> mixin("class MyDynamicClassName { }");
> MyDynamicClassName cls = new MyDynamicClassName;
> ```
Yes but not at runtime
More information about the Digitalmars-d-learn
mailing list