Reputation: 8920
I am trying this simple template template parameter
example:
template <typename T, template <typename> class Cont>
class Stack {
//...
private:
Cont<T> s_;
};
int main(){
Stack<int,std::vector> aStack1;
}
When I am trying to compile the compiler complains: error type mismatch at argument 2 in template parameter list...
Do I have an error or maybe the problem is in the edition of my compiler? I am using g++ on Windows with Mingw
Upvotes: 1
Views: 672
Reputation: 7881
This is becuase, despite having default arguments, std::vector has 2 template arguments (template < class T, class Alloc = allocator<T> >
). The following code works just fine:
#include <vector>
template <typename T, template <typename> class Cont>
class Stack {
//...
private:
Cont<T> s_;
};
template <typename T>
using my_vector = std::vector<T>;
int main(){
Stack<int,my_vector> aStack1;
}
Upvotes: 5