Any C++ experts here? I'm currently taking a course on Data Structures and Algorithms in C++. The professor has given us a header file for us to implement a Stack. However, I think the header file is slightly incorrect:
Code:
template <typename E>
class Stack {
public:
Stack();
~Stack();
void push(const E& e);
const E& pop();
const E& top() const;
int size () const;
bool empty() const;
Take note of the pop() method. It is returning a reference to an element that exists in the stack. However, this element has been
removed from the stack -- so how could it possibly return a reference to it? It would have to be a copy, right? I'm trying to convince the professor this is wrong since we're not supposed to modify the header file other than for private members.