Object.factory
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Thu Jun 7 12:53:12 PDT 2007
dennis luehring wrote:
>> Note that if you know the class name at compile time, you don't need
>> Object.factory: you can use a mixin statement instead, which works
>> just as you'd
>> expect and without runtime costs:
>> mixin("MyClass a = new MyClass;");
>
> and why not just
>
> MyClass a = new MyClass;
>
> why is there a need for mixin the code???
>
>
If "MyClass" were being stored as a string somewhere, being selected by
deep versioning or by some other compile-time process (like CTFE), then
the mixin method becomes rather useful.
const CLAZZ = elaborateCTF() ;
mixin("auto a = new " ~ CLAZZ ~ ";");
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list