[计算机科学经

Hpp templatetypename t class s public void f

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: / pop 元素 T top() const; // 傳回 stack 的頂端元素 bool empty() const { // stack 是否為空 return elems.empty(); } // 賦予㆒個「元型別為 T2」的 stack template<typename T2, template<typename ELEM2, typename = std::allocator<ELEM2> > class CONT2> Stack<T,CONT>& operator= (Stack<T2,CONT2> const&); }; template <typename T, template <typename,typename> class CONT> void Stack<T,CONT>::push (T const& elem) { elems.push_back(elem); // 追加元素 } template<typename T, template <typename,typename> class CONT> void Stack<T,CONT>::pop () { if (elems.empty()) { throw std::out_of_range("Stack<>::pop(): empty stack"); } elems.pop_back(); // 移除最後㆒個元素 } template <typename T, template <typename,typename> class CONT> T Stack<T,CONT>::top () const { if (elems.empty()) { throw std::out_of_range("Stack<>::top(): empty stack"); } return elems.back(); // 傳回最後㆒個元素的拷貝 } C++ Templates - The Complete Guide 5...
View Full Document

This note was uploaded on 08/25/2012 for the course EECS 101 taught by Professor Wre during the Fall '12 term at Beacon FL.

Ask a homework question - tutors are online