[计算机科学经

7 template parameter typename nested classesmember

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: p" int main() { int i = 42; std::cout << "max(7,i): " << ::max(7,i) << std::endl; double f1 = 3.4; double f2 = -6.7; std::cout << "max(f1,f2): " << ::max(f1,f2) << std::endl; C++ Templates - The Complete Guide 2.1 Function Templates 初窺 11 std::string s1 = "mathematics"; std::string s2 = "math"; std::cout << "max(s1,s2): " << ::max(s1,s2) << std::endl; } 程式呼叫了 max()㆔次。第㆒次所給引數是兩個 int,第㆓次所給引數是兩個 double,最後㆒ 次給的是兩個 std::string。每㆒次 max()均比較兩值取其大者。程式運行結果為: max(7,i): 42 max(f1,f2): 3.4 max(s1,s2): mathematics 注意程式對 max()的㆔次呼叫都加了前綴字 "::" ,以便確保被喚起的是我們在全域命名空間 (global namespace)㆗定義的 max()。標準程式庫內也有㆒個 std::max() 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