This is a example straight from the book:
template <class T>
class stack
{
public:
stack();
stack(const stack&);
stack & operator=(const stack&);
~stack();
T& top();
void push(const T&);
void pop();
//few more functions
}
I have following question :
Why the top’s return type is not stack& and why the overloaded assignment’s argument is not T& ?
Rgds,
Softy
Because the purpose of
topis to return the element at the top of the stack, not the stack itself!