Stack isn't popping off correct data? So, I was working on a project where I needed to get a random object from a stack, so to make sure my design was correct, I made a dummy program that does nothing but fill a stack with data, then print it out.


why in the world is nothing coming out of the stack but -1s??

Here's the stack.h file.

http://pastebin.com/vjhNLpNu
You're not telling it how big your stack should be, and it defaults to 0 entries, which means nothing gets stored.

class Stack
{
private:
    int *p;
    int top,length;

public:
    Stack(int = 0);  &lt;&lt;== CONSTRUCTOR - DEFAULT SIZE IS 0
    ~Stack();

    void push(int);
    int pop();
    void display();
};


When you make your Stack object you must give it a size for the number of entries in the stack:

Stack stack(4);