下面是一个示例代码:模板的模板参数 - 类型/值不匹配错误
#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();
}
而且我看到了编译器(GCC)是不开心:
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
标准栈容器具有这种形式:
template <class Type, class Container = deque<Type> > class stack
;
含义我应该没问题,只能在这里传递一个模板参数!
有关如何解决此问题的任何想法? 谢谢