Re: [問題] 限制 Template 的具現化
※ 引述《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
04/29 16:30, 2F
推
04/29 19:00, , 3F
04/29 19:00, 3F
推
04/30 09:58, , 4F
04/30 09:58, 4F
→
04/30 23:55, , 5F
04/30 23:55, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章