Re: [問題] template問題

看板C_and_CPP (C/C++)作者 ( )時間14年前 (2011/12/23 13:34), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《tyc5116 (累人啊....)》之銘言: : template<typename T> : class RParam{ : public: : typedef typename IfThenElse<IsClass<T>::No, : T, : T const&>::ResultT Type : //判斷是否為Class,是Type則為T,不是Type則為ResultT : template<typename T1,typaname T2> : void foo(typename RParam<T1>::Type p1, : typename RParam<T2>::Type p2){} : int main(){ : MyClass1 mc1; : MyClass2 mc2; : foo<MyClass1,MyClass2>(mc1,mc2); : return 0; : } : 書上說foo無法經由引數推導 : 因為template parameters只出現在函式參數的qualifiers上 : 因此呼叫端必須明確指定templates arguments. : 對這句話的意思不清楚,可以麻煩解釋一下嗎? 謝謝 : p.s 程式碼有部份省略沒打,不知道這樣的表達方式夠不夠清楚 : 不夠的話我在補上其餘的程式碼 Final Committee Draft of ISO/IEC IS 14882 14.8.2.5 Deducing template arguments from a type 4. In most cases,[...] If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails. 5. The non-deduced contexts are: - The nested-name-specifier of a type that was specified using a qualified-id. [...] 對照你的code RParam<T1>::Type ==> qualified-id specifying T1 ==> type in nested-name-specifier -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.72.92.133
文章代碼(AID): #1Ez1BYg8 (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
1
1
完整討論串 (本文為第 3 之 3 篇):
1
1
文章代碼(AID): #1Ez1BYg8 (C_and_CPP)