Here’s a sample code:
#include <stack>
#include <cstddef>
template <std::size_t N,
template <class> class Stack = std::stack
>
class Tower : protected Stack<int>
{
public:
Tower() : Stack<int>(N)
{
}
};
int main(int argc, char **argv)
{
Tower<5L> tower1();
}
And I see the compiler (gcc) is not happy:
file.cpp: In function 'int main(int, char**)':
file.cpp:18:11: error: type/value mismatch at argument 2 in template parameter
list for 'template<long unsigned int N, template<class> class Stack> class Tower'
file.cpp:18:11: error: expected a template of type 'template<class> class Stack',
got 'template<class _Tp, class _Sequence> class std::stack'
file.cpp:18:21: error: invalid type in declaration before ';' token
The standard stack container has this form:
template <class Type, class Container = deque<Type> > class stack;
Meaning I should be fine to pass only one template argument here!
Any thoughts on how to resolve this?
Thanks
'template<class> class Stack',shows the problem.got 'template<class _Tp, class _Sequence> class std::stack'
Here is what
std::stacklooks likeAs you can see there is a second parameter.
Adding:
should make it compile.