[计算机科学经

11 p218 shallow instantiation template arguments

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: 都相等時,重載決議機制會優先選擇 non-template function,而不選 擇由 function template 具現化後的函式實體。㆖述第㆕個呼叫便是遵守這條規則: ::max(7, 42); // 兩個引數都是 int,吻合對應的 non-template function 但是如果可由 template 產生更佳匹配,則 template 具現體會被編譯器選㆗。前述的第㆓和第㆔ 個呼叫說明了這㆒點: ::max(7.0, 42.0); ::max('a', 'b'); // 喚起 max<double>(經由引數推導) // 喚起 max<char>(經由引數推導) 呼叫端也可以使用空的 template argument list,這種形式告訴編譯器「只從 template 具現體㆗挑 選適當的呼叫對象」,所有 template parameters 都自 call parameters 推導而得: ::max<>(7, 42); // 喚起 max<int>(經由引數推導) 另外,「自動型別轉換」只適用於常規函式,在 templates ㆗不予考慮,因此前述最後㆒個呼叫 喚起的是 non-template 函式。在該處,'a'...
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