code:
template <typename element_type, typename container_type = std::deque<element_type> > class stack { public: stack() {} template <typename CT> stack(CT temp) : container(temp.begin(), temp.end()) {} bool empty(); private: container_type container; }; template <typename element_type, typename container_type = std::deque<element_type> > bool stack<element_type, container_type>::empty() { return container.empty(); }
When I compile it gives the error.
default argument for template parameter for class enclosing
'bool stack<element_type,container_type>::empty()'
Why is the compiler complaining and how can I make it work?
You attempt to provide a default argument for the second template parameter to stack
twice. Default template arguments, just like default function arguments, may only be defined once (per translation unit); not even repeating the exact same definition is allowed.
Just type the default argument at the beginning where you define the class template. After that, leave it out:
template<typename element_type,typename container_type> bool stack<element_type,container_type>::empty(){ return container.empty(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With