 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
template
<class TYPE> class stack {
|
|
private:
|
|
TYPE * stack_array;
|
|
const int stack_size;
|
|
int stack_index;
|
|
public:
|
|
stack (int size=100): stack_size(size),
stack_index(0) { stack_array = new
|
|
TYPE[size];
} ...
|
|
};
|
|
template
<class TYPE> void stack<TYPE>::push(TYPE item) {
|
|
if (stack_index < stack_size) {
|
|
stack_array[stack_index] = item;
|
|
++stack_index; } }
|
|
//An
explicit specialization
|
|
template
<> void stack <char *>::push(char * item) {
|
|
if (stack_index < stack_size) {
|
|
stack_array[stack_index] = new
char[strlen(item)+1];
|
|
strcpy(stack_array[stack_index],
item);
|
|
++stack_index; } }
|
|