Re: [問題] 限制 Template 的具現化

看板C_and_CPP (C/C++)作者 (眠月)時間14年前 (2012/04/29 13:16), 編輯推噓3(302)
留言5則, 5人參與, 最新討論串2/2 (看更多)
※ 引述《birdhackor (夜殘狼)》之銘言: : 有沒有辦法指定他只能具現化特定型別的函數呢? #include <type_traits> class Base {} ; class Derived {} ; template < typename T > T operator+( const T& lhs, const typename std::enable_if< std::is_base_of<Base, T>::value, T >::type& rhs) { ... } 這樣就只有 Base 跟繼承他 Base 的 class 會套用這個 operator+。 因為你剛開始學 template,細節就先不說了,先把他當作一個 magic 就好了 /_\ -- To iterate is human, to recurse, divine. 遞迴只應天上有, 凡人該當用迴圈.   L. Peter Deutsch -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 182.235.170.158

04/29 15:47, , 1F
我來試看看~謝謝
04/29 15:47, 1F

04/29 16:30, , 2F
magic XD
04/29 16:30, 2F

04/29 19:00, , 3F
wow~~~magic!!
04/29 19:00, 3F

04/30 09:58, , 4F
太神奇了!傑克!
04/30 09:58, 4F

04/30 23:55, , 5F
loveme00835 holymars 對兩位來說只是基本技能
04/30 23:55, 5F
文章代碼(AID): #1FdCwW9t (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1FdCwW9t (C_and_CPP)