Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Stack and Node files not compiling right. I have a core dump error showing up at the bool expression. please help. //Node.cpp template Node

c++ Stack and Node files not compiling right. I have a core dump error showing up at the bool expression. please help.

//Node.cpp

template Node::Node(T entry) { m_entry = entry; m_next = nullptr; }

template T Node::getEntry() const { return(m_entry); }

template void Node::setEntry(T entry) { m_entry = entry; }

template Node* Node::getNext() const { return(m_next); }

template void Node::setNext(Node* next) { m_next = next; }

//Stack.cpp

template Stack::Stack(const Stack& orig) { Node* origNodes = orig.m_top; while(origNodes != nullptr) { push(origNodes-> getEntry()); origNodes = origNodes -> getNext(); numPeople++; } }

template void Stack::push(T entry) { Node* temp1 = new Node(entry, m_top); m_top= temp1; numPeople++; }

template bool Stack::isEmpty() { if(m_top == nullptr) {return (true);} else { return(false); } }

template void Stack::pop() { try { Node* temp = m_top; T temp1= m_top -> getEntry(); m_top= temp-> getNext(); delete temp ; numPeople--; } catch(std::runtime_error rte) { std::cout << rte.what(); } }

template T Stack::peek() const { try { return(m_top-> getEntry()); } catch(std::runtime_error rte) { std::cout << rte.what(); return("No one"); } }

template Stack::~Stack() { while (isEmpty()!= false) { m_top->setEntry(nullptr); m_top->getNext(); } delete[] m_top; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions