這兩天在飲水思源的C板,關於C++模板的類型轉換的一個討論,後面是我的解答。
原問題
今天在書上看到模板演繹的時候可以允許cast-down,於是我寫了個東西:
template <bool _Test, class _Type = void> struct enable_if { }; template<class _Type> struct enable_if<true, _Type> { typedef _Type type; }; class A { }; class B : A { }; template <typename T> struct …