#include template class stackNode { public: T data; stackNode *next; stackNode(const T& el,stackNode *below=nullptr) : data(el),next(below) {} }; class stackEmptyException : public std::exception { public: stackEmptyException() noexcept {} const char* what() const { return "Attempt to pop empty stack."; } }; template class stack { public: stack() : head(nullptr) {} stack(const stack& other) = delete; stack(stack&& other) = delete; ~stack() { while(head != nullptr) { stackNode *toDelete = head; head = head->next; delete toDelete; } } stack& operator=(const stack& other) = delete; stack& operator=(stack&& other) = delete; bool isEmpty() const { return head == nullptr; } void push(const T& item) { head = new stackNode(item,head); } const T& top() { if(this.isEmpty()) throw stackEmptyException(); return head->data; } void pop() { if(this.isEmpty()) throw stackEmptyException(); stackNode *toDelete = head; head = head->next; delete toDelete; } private: stackNode *head; };