Code Fragment: ArrayStack2



  // ... (continuation of ArrayStack)
  ArrayStack(const ArrayStack& st);	// copy constructor
  					// assignment operator constructor
  ArrayStack& operator=(const ArrayStack& st);
  ~ArrayStack() 			// destructor
    { delete [] S; }
};

template <typename Object>		// copy constructor
ArrayStack<Object>::
ArrayStack(const ArrayStack& st) {
  capacity  = st.capacity;
  t         = st.t;
  S         = new Object[capacity];
  for (int i = 0; i <= t; i++) {	// copy contents
    S[i] = st.S[i];
  }
}

template <typename Object>		// assignment operator
ArrayStack<Object>& ArrayStack<Object>::
operator=(const ArrayStack& st) {
  if (this != &st) {			// avoid self copy (x = x)
    delete [] S;			// delete old contents
    capacity  = st.capacity;
    t         = st.t;
    S         = new Object[capacity];
    for (int i = 0; i <= t; i++) {	// copy contents
      S[i] = st.S[i];
    }
  }
  return *this;
}