[计算机科学经

C basicstracercpp include tracerhpp long long long

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: <string> // 傳回兩個任意型別值的較大者(call-by-reference) template <typename T> inline T const& max (T const& a, T const& b) { return a < b ? b : a; } C++ Templates - The Complete Guide 2 18 Function Templates(函式模板) // 傳回兩個 C-style 字串的較大者(call-by-value) inline char const* max (char const* a, char const* b) { return std::strcmp(a,b) < 0 ? b : a; } // 傳回㆔個任意型別值的最大者(call-by-reference) template <typename T> inline T const& max (T const& a, T const& b, T const& c) { return ::max (::max(a,b), c); // 當 max(a,b)採用 by value 形式時,此錯誤 } int main() { ::max(7, 42, 68); // OK const char* s1 = "frederic"; const char* s2 = "anica"; const char* s3 = "lucas"; ::max(s1, s2, s3); // ERROR } 本例㆗針對㆔個 C-style 字串呼叫 max(),會出現問題。以㆘這行述句是錯誤的: return ::max (::max(a,b), c); 因為 C-style 字...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online