Dynamic Stack  «Prev 

Example of using stack Constructors

The following lines of code use the ch_stack constructors:
ch_stack  data;     //creates s[100]
ch_stack  d[N];     //creates N 100 element ch_stacks
ch_stack  w(4, "ABCD"); //w.s[0]='A'...w.s[3]='D'
If we include each of these constructors in the ch_stack class definition, which one is invoked depends on the calling statement.
The statement
ch_stack  data;

would invoke the default constructor since it supplies no arguments, initializing it to s[100].

The statement
ch_stack  d[N];

would also invoke the default constructor, since [n] is not a function argument. As a subscript, [N] defines d as an array. Thus, you create an array of "N" ch_stack objects, each initialized by the default to s[100].
The statement
ch_stack  w(4, "ABCD");

would invoke the second constructor so that w.s[0] = 'A' and w.s[3] = 'D'.