c++ - Working with templates -
im studying c++ templates , there's don't understand. far understand if have following generic class
template <class t> class a{ ... }
to provide specific specialization of class, int
objects, you'd define following:
template<> class a<int>{ ... }
however, have been seeing cases similar following:
original class is,
template <class t, int size> class buffer{ ... }
then speciliazed class objects of type int
is,
template <int size> class buffer<int, size>{ ... }
i'm confused why specilization int
not following:
template<> class bufffer<int, int size>{ ... }
can please explain.
this buffer
template has 2 template parameters. first type parameter because begins class
, , second non-type parameter because begins int
.
what seeing partial specialization on first parameter. note template arguments template specialization totally independent of template arguments original template (this 1 of major things confused me when learning this). example, work as:
template <int n> class buffer<int, n> { ... };
it giving specialization when first template argument of buffer
type int
, second int
value.
whenever start template <>
(empty brackets), explicit specialization specifying all of template arguments. example, do:
template <> class buffer<int, 1> { ... };
this specialization when first template argument int
type , second value 1
.
Comments
Post a Comment