On Fri, Jun 02, 2017 at 11:05:43PM +0000, Mark via Digitalmars-d-learn wrote:
[...]
> Stefan, what do you mean that it must be a template?
> 
> Am I supposed to write template Struct(T) { class Stack { ... } }?

No, he means to turn class Stack into a template by adding a template
parameter to it, like I suggested.

In D, writing `class Stack(T) { ... }` is equivalent to writing:

        template Stack(T) {
                class Stack { ... }
        }

It's the so-called eponymous template.

The reason you need a template here is because, unlike Java, D does not
do type erasure to achieve generic types. Full type information is
preserved, so Stack!int and Stack!string represent distinct,
incompatible types.


T

-- 
Never wrestle a pig. You both get covered in mud, and the pig likes it.

Reply via email to