[计算机科学经

5 explicit instantiation 159 2 obj ti ii 3 ii 1 4

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: sh(7); C++ Templates - The Complete Guide 5.4 Template Template Parameters(雙重模板參數) 55 // 操控 float stack floatStack.push(7.7); // 賦予㆒個「不同型別」的 stack floatStack = intStack; // 列印 float stack std::cout << floatStack.top() << std::endl; floatStack.pop(); std::cout << floatStack.top() << std::endl; floatStack.pop(); std::cout << floatStack.top() << std::endl; floatStack.pop(); } catch (std::exception const& ex) { std::cerr << "Exception: " << ex.what() << std::endl; } // int stack,以 vector 為其內部容器 Stack<int,std::vector> vStack; // ... vStack.push(42); vStack.push(7); std::cout << vStack.top() << std::endl; vStack.pop(); } 程式運行的輸出結果為: 7 42 Exception: Stack<>::top(): empty stack 7 注意,template template parameter 是極晚近才加入的 C++ 特性,因此㆖面這個程式可作為㆒個 極佳工具,用來評估你的編譯器對 template 特性的支...
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