作者godman362 (Shizuru)
看板NUU_CSIE
標題Re: [發問] 快一個人來解決我的問題
時間Sun Mar 8 18:03:05 2009
※ 引述《godman362 (Shizuru)》之銘言:
: template <class T, class U>
: 和
: template <class T>
: template <class U>
: 差別在哪裡ˊˋ
: 為什麼這樣寫可以過:
: template <class T, class U>
: void show(T a, U b)
: {
: ...
: ...
: }
: 這樣寫就不能過:
: template <class T>
: template <class U>
: void show(T a, U b)
: {
: ...
: ...
: }
: 哭哭
對函數show而言,上半段的寫法,它知道T, U都是資料型態
但下半段的寫法,它只知道U是資料型態,T則未定義!
以上,
周董回應。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.118.112.132
1F:推 littleast:所以這是因為函數不懂這種寫法嗎? 03/08 18:05
2F:→ godman362:不,是因為show看不到tempalte <class T> 03/08 18:26
3F:→ godman362:因為template<class X>的部份只會給他的下一行程式看到 03/08 18:27
4F:→ godman362:所以他只看的到template <class U> 而看不到 <class T> 03/08 18:27
5F:推 littleast:哦~看懂了!謝謝指教XD 03/08 19:21
6F:→ godman362:聽懂當然是最好,可是會不會用還是其次 03/08 20:25
7F:推 littleast:你說到重點了XD 03/08 20:39