I am slightly confused about c++ template.
Considering the template below
template<class TYPE>
void function(TYPE data)
and
template<typename TYPE>
void function(TYPE data)
My confusion is exactly what is the difference between typename and class used as variable identify or type.
For designating (type) template parameters, the two are exactly identical, just like int
/signed int
, or &&
/and
: template <typename>
/template <class>
.
A curious restriction applies to template template parameters up to C++14:
template <template <typename> class Tmpl> struct Foo;
// ^^^^^
Here only the keyword class
is allowed to designate the template template parameter.
After C++14, you will be able to consistently use either class
or typename
everywhere:
template <template <typename> typename Tmpl> struct Foo;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With