????? template <typename T>
?T f(T a1,T a2)
{
.........................
}
顯示實(shí)參
f<int >(1,2);
顯示實(shí)例化
template? int f<int >(int ,int);(申明)
顯示特化
? template <> int f<int> (int,int)(定義)
{
????? ...........
}
強(qiáng)制 從模版中挑選
?
f<>(2,3);
在函數(shù)調(diào)用,取函數(shù)地址時(shí) 實(shí)參推演(左值,限定,基類)
?int (* p)(int ,int)=&f;???? int(*p) (int ,int )=& f<int,int>
? f(2,3);???????????????????????????? f<int,int>(2,3);
1.編譯模版時(shí),編譯器檢查
2.實(shí)例化時(shí)(在實(shí)例化點(diǎn) 再編譯),編譯器檢查
函數(shù)模版 只能出現(xiàn)在模版定義中
函數(shù)模版實(shí)例 可以出現(xiàn)在模版定義和非定義中
//////////////////////
1.非模版函數(shù)優(yōu)先級(jí)高
2.候選---〉可行實(shí)例化(有特化否〈)(有非模版否)--〉選中
3.依賴模版參數(shù)的在實(shí)例點(diǎn)解析,不依賴的在模版定義時(shí)解析
posted on 2006-05-27 15:31
黃大仙 閱讀(998)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
c++