c++ - Two classes that differ only with template parameters -
is possible create 2 template classes same name, differ in number of template parameters? example,
template<typename t> struct tuple { t item; }; template<typename t1, typename t2> struct tuple { t1 item1; t2 item2; };
not syntax used, there alternative solutions:
option #1:
(c++03)
template <typename t1, typename t2 = void> struct tuple { t1 item1; t2 item2; }; template <typename t1> struct tuple<t1, void> { t1 item; };
option #2:
(c++11)
template <typename...> struct tuple; template <typename t1> struct tuple<t1> { t1 item; }; template <typename t1, typename t2> struct tuple<t1, t2> { t1 item1; t2 item2; };
Comments
Post a Comment