下面是一個示例代碼:模板的模板參數 - 類型/值不匹配錯誤
#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
;
含義我應該沒問題,只能在這裏傳遞一個模板參數!
有關如何解決此問題的任何想法? 謝謝