I've seen both of them a lot when defining templates, what's the difference between these two?
And the other question is, I saw a template like this on Wikipedia What does each keyword mean here?
template < template < typename, typename > class Container, typename Type >
class Example
{
Container< Type, std::allocator < Type > > baz;
};
Usually, you can use either typename
or class
.
template<class T>
class Foo{};
///Two are the same
template<typename T>
class Foo{};
Special cases where the two cannot be mixed
If you are writing types related to other template parameters, you can only write the typename
keyword.
template<typename param_t>
class Foo
{
typedef typename param_t::baz sub_t;
};
The second question is here.
template template
must use the class
keyword as follows, and cannot be mixed with typename
at this time
template < template < typename, typename > class Container, typename Type >
In addition, when instantiating a template, you can only write class
as follows:
template class Foo<int>;
© 2024 OneMinuteCode. All rights reserved.