c++ - "Expected class-name"...Issue in destructor implementation -
i'm trying implement stack , queue. i've been provided code test both stack , queue (to see whether respective functions work properly).
i've implemented functions of both stack , quete,, when trying compile them error: in destructor `stack::~stack()' expected class-name before '(' token in both of them.
following generic stack class:
template <class t> class stack { list<t> list; public: stack(); stack(const stack<t>& otherstack); ~stack(); }
the list class:
template <class t> class list { listitem<t> *head; public: list(); list(const list<t>& otherlist); ~list(); }
now destructor list class working fine. keeping in mind, implementation destructor was:
template <class t> stack<t>::~stack() { list.~list(); }
what doing wrong here?
you should (almost) never phone call destructor explicitly. when stack
's life ends, automatically phone call destructors of members. don't need anything. list
destroyed automatically.
if had pointer, p
, dynamically allocated object member, then need cleaning in destructor doing delete p;
. here, don't. list
destroyed automatically.
c++ class linked-list stack destructor
No comments:
Post a Comment