Re: Instantiating a class with different types at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 20:57:28 UTC, Namespace wrote: class Example(L, R) { L _left; R _right; this(L l, R r) { _left = l; _right = r; } } That was fast! But I needed the second reply in order to understand yours. Thanks anyway.

Re: Instantiating a class with different types at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 21:06:58 UTC, ag0aep6g wrote: Turn Example into a template, and add a free function for nice construction: class Example(Type_left, Type_right) { /* ... as you had it ... */ } Example!(L, R) makeExample(L, R)(L x, R y) { return new Example!(L, R)(x,

Re: Instantiating a class with different types at runtime

2016-11-27 Thread ag0aep6g via Digitalmars-d-learn
On 11/27/2016 09:52 PM, Marduk wrote: 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

Re: Instantiating a class with different types at runtime

2016-11-27 Thread Namespace via Digitalmars-d-learn
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; } Suc

Instantiating a class with different types at runtime

2016-11-27 Thread Marduk via Digitalmars-d-learn
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: