Re: Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
On Friday, 2 June 2017 at 23:34:14 UTC, Ali Çehreli wrote: You've probably seen H. S. Teoh's answer but still... :) ... Ali Awesome, thanks everyone!

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Ali Çehreli via Digitalmars-d-learn
You've probably seen H. S. Teoh's answer but still... :) On 06/02/2017 04:05 PM, Mark wrote: > Am I supposed to write template Struct(T) { class Stack { ... } }? Not necessary because in this case it's the same thing as class Stack(T) { // Don't templatize functions in here (in general) }

Re: Trouble with SList for generic Stack class

2017-06-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 02, 2017 at 11:05:43PM +, 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,

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
Awesome. That worked. On Friday, 2 June 2017 at 22:30:28 UTC, Stefan Koch wrote: On Friday, 2 June 2017 at 22:21:07 UTC, Mark wrote: Hello, I am trying to make a class that can accept any type as an argument. [...] the stack class needs to be a template as well. This is not java ;)

Re: Trouble with SList for generic Stack class

2017-06-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 02, 2017 at 10:21:07PM +, Mark via Digitalmars-d-learn wrote: > Hello, > > I am trying to make a class that can accept any type as an argument. > > Here is the class: > > > import std.container: SList; > > > class Stack { > > private SList!T list; > private int _size; >

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 22:21:07 UTC, Mark wrote: Hello, I am trying to make a class that can accept any type as an argument. [...] the stack class needs to be a template as well. This is not java ;)

Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
Hello, I am trying to make a class that can accept any type as an argument. Here is the class: import std.container: SList; class Stack { private SList!T list; private int _size; this(T)() { list = SList!T; _size = 0; } public void push(T)(T item) {