So I have a class of the form:
template <typename T, template <typename T> class Container = std::vector>
class MyArray : Container<T>
{
...
}
Now I'm trying to instantiate this as
template <typename T>
class MyClass
{
MyArray<T> array;
}
This is producing an error:
error: type/value mismatch at argument 2 in template parameter list for 'template<class T, template<class T> class Container> class MyArray'
MyArray<T> y;
And it points to the >
of MyArray<T>
.
What's wrong in this? Why can't I have a default template parameter?
Thanks.
The issue is that
std::vector
takes two template arguments: the type and the allocator. Many other container types will takes additional policy arguments which have defaults to allow you to instantiate likeT<U>
.In order to support this, you can say that your template template parameter should take at least one template parameter using variadic templates (
typename...
):