First Steps: Dynamic class instantiation
Julio César Carrascal Urquijo
jcesar at phreaker.net
Sun Jan 28 09:38:34 PST 2007
Thomas wrote:
> Hi
>
> I'm just making my first steps to understand D, and sometimes I'm a little bit offroad as I do not know C/C++, just PHP, Javascript etc.
>
> I would like to write a small shell application with a small bundle of functionalities. As a first step, the user must choose which function to use (I already got that part). Than she must enter some information for the function to work on.
>
> I thought of doing this by creating classes for each functionality implementing the same interface and creating an array in main() that somehow refers to these classes. There the trouble starts.
>
> I don't know how to create such an array, and of which type it has to be. To be more specific, I provide you with a PHP example of what I want to do:
>
> $selected = 1;
> $classes = array('class1','class2');
> $className = $classes[$selected];
> $object = new $className;
>
> Thanks for any help.
>
> Thomas
More information about the Digitalmars-d
mailing list