www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dynamic creation of instannce

reply maa lagraine.com writes:
hello

I kust we,nt thru a lot of D documentation
D solve apparently to me a lot of what I hate In C.
But I still have a big question
can you in D write

new toto;

were toto is not a class name but a variable holding a class name
or do I have to go thru factories as usual
(except that it would be more simplle in D)

Thanks
Maa
Apr 24 2006
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<maa lagraine.com> wrote in message news:e2io95$2cah$1 digitaldaemon.com...
 can you in D write

 new toto;

 were toto is not a class name but a variable holding a class name
 or do I have to go thru factories as usual
_What?_ Are you asking if it's possible to write SomeclassToto; new toto; as a shortcut for SomeClass toto = new SomeClass(); ? If that's what you're asking, then no, there isn't. You can, however, write auto toto = new SomeClass(); Which can save you a couple keystrokes.
Apr 24 2006
prev sibling parent Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
maa lagraine.com wrote:
 hello
 
 I kust we,nt thru a lot of D documentation
 D solve apparently to me a lot of what I hate In C.
 But I still have a big question
 can you in D write
 
 new toto;
 
 were toto is not a class name but a variable holding a class name
 or do I have to go thru factories as usual
 (except that it would be more simplle in D)
 
 Thanks
 Maa
 
 
If you're looking for runtime reflection, like in Java where you can do something like 'Class c = new Class("Foo")', which would be equivalent to 'Class c = new Foo()', then, no. D doesn't have a reflection API - at least not yet.
Apr 24 2006