Original Post
I''m reading C++ Templates The complete guide and try to compile the stack example found on page 52-54 in vc++ 7.1
template<typename T, template <typename Elem, typename = std::allocator<Elem> >
class Container = std::deque>
class Stack
{
public:
void Push(const T &);
void Pop();
T Top() const;
bool Empty() const { return elems.empty(); }
template<typename T2, template<typename Elem2, typename = std::allocator<Elem2> >
class Container2>
Stack<T, Container> &operator=(const Stack<T2, Container2> &);
private:
Container<T> elems;
};
template<typename T, template<typename, typename> class Container>
void Stack<T, Container>::Push(const T &elem)
{
elems.push_back(elem);
}
template<typename T, template<typename, typename> class Container>
void Stack<T, Container>::Pop()
{
if (elems.empty())
{
throw std::out_of_range("Stack<>::Pop(): empty stack");
}
elems.pop_back();
}
template<typename T, template<typename, typename> class Container>
T Stack<T, Container>::Top() const
{
if (elems.empty())
{
throw std::out_of_range("Stack<>::Top(): empty stack");
}
return elems.back();
}
template<typename T, template<typename, typename> class Container>
template<typename T2, template<typename, typename> class Container2>
Stack<T, Container> &Stack<T, Container>::operator=(const Stack<T2, Container2> & op2)
{
if (static_cast<void *>(this) == static_cast<void *>(&op2))
{
return *this;
}
Stack<T2, Container2> temp(op2);
elems.clear();
while (!temp.Empty())
{
elems.push_front(temp.Top());
temp.Pop();
}
return *this;
}I get two errors when I try to compile it:
error C3201: the template parameter list for class template ''std::deque'' does not match the template parameter list for template parameter ''Container''
error C2976: ''Container'' : too few template arguments
I have looked over the code a few times and don''t find any differences from the books code, except for the names.