MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / pop

Method pop

Examples/NoModules/Chapter 17/Ex17_04/Stack.h:85–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83// Pop an object off the stack
84template <typename T>
85T Stack<T>::pop()
86{
87 if (isEmpty()) // If it's empty pop() is not valid so throw exception
88 throw std::logic_error {"Stack empty"};
89
90 auto* next {m_head->m_next}; // Save pointer to the next node
91 T item {m_head->m_item}; // Save the T value to return later
92 delete m_head; // Delete the current head
93 m_head = next; // Make head point to the next node
94 return item; // Return the top object
95}
96
97template <typename T>
98bool Stack<T>::isEmpty() const { return m_head == nullptr; }

Callers 8

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected