[计算机科学经

4 implementation schemes 157 obj obj lib linker

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: 54 高階基本技術 template <typename T, template <typename,typename> class CONT> template <typename T2, template <typename,typename> class CONT2> Stack<T,CONT>& Stack<T,CONT>::operator= (Stack<T2,CONT2> const& op2) { if ((void*)this == (void*)&op2) { // 是否賦值給自己 return *this; // 譯註:請見 p47 之「英文版勘誤」 } Stack<T2,CONT2> tmp(op2); // 創建 assigned stack 的㆒份拷貝 elems.clear(); while (!tmp.empty()) { elems.push_front(tmp.top()); tmp.pop(); } return *this; // 移除所有元素 // 複製所有元素 } #endif // STACK_HPP ㆘面程式使用了㆖述最終版本的 stack: // basics/stack8test.cpp #include #include #include #include #include <iostream> <string> <cstdlib> <vector> "stack8.hpp" int main() { try { Stack<int> intStack; Stack<float> floatStack; // stack of ints // stack of floats // 操控 int stack intStack.push(42); intStack.pu...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online