Instantiating a class with different types at runtime

Marduk via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 27 12:52:06 PST 2016


Dear all,

I would like to have a kind of template class like the following:

   class Example {

     this(Type_left x, Type_right y) {
       this.left = x;
       this.right = y;
     }

     Type_left left;
     Type_right right;

   }

Such that at runtime I can instantiate it with different types:

new Example(int a, int b);

new Example(int a, string b);

I have read about templates and abstract classes, but I have not 
figured how to get this to work. Thanks.


More information about the Digitalmars-d-learn mailing list