On Sunday, 27 November 2016 at 20:52:06 UTC, Marduk wrote:
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.

class Example(L, R)
{
    L _left;
    R _right;

    this(L l, R r)
    {
        _left = l;
        _right = r;
    }
}

Reply via email to