c++ - Why do i need to declare underflow_error -


in below code, error

stack.cpp: in member function ‘t* stack<t>::pop()’: stack.cpp:53: error: there no arguments ‘underflow_error’ depend on template parameter, declaration of ‘underflow_error’ must available

what rationale behind declaring class underflow_error; ?

#include <iostream> using namespace std;  template <class t> class stack { public:     stack(): head(null) {};     ~stack();      void push(t *);     t* pop();  protected:     class element {     public:             element(element * next_, t * data_):next(next_), data(data_) {}             element * getnext() const { return next; }             t * value() const {return data;}     private:             element * next;             t * data;     };      element * head; };  template <class t> stack<t>::~stack() {     while(head)     {             element * next = head->getnext();             delete head;             head = next;       }  }  template <class t> t * stack<t>::pop() {     element *popelement = head;     t * retdata;      if(head == null)             throw underflow_error("stack empty");      retdata = head->value();     head = head->getnext();      delete popelement;     return retdata; } 

you have add

#include <stdexcept> 

when use underflow_error.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -