This question is about improving my C++ coding skills. I was asked to implement a simple static integer stack in C++ as an assignment. I've come up with the following code:

class myStaticIntStack
{

    int stackSize;
    int storedElements;
    int *elements;

public:

    myStaticIntStack();
    myStaticIntStack( int aNumber );

    ~myStaticIntStack();

    int peek();

    int pop();

    void push( int element );

};

myStaticIntStack::myStaticIntStack()
{
    this-&gt;stackSize = 1;
    this-&gt;elements = new int(0);
    this-&gt;storedElements = 0;
}

myStaticIntStack::myStaticIntStack( int stackSize )
{
    this-&gt;stackSize = stackSize;
    this-&gt;elements = new int[ stackSize ];
    this-&gt;storedElements = 0;
}

myStaticIntStack::~myStaticIntStack()
{
    if( this-&gt;elements != NULL )
    {
        if( stackSize &gt; 1 )
            delete[] this-&gt;elements;
        else
            delete this-&gt;elements;
    }

}

void myStaticIntStack::push( int newElement )
{
    if( this-&gt;storedElements == this-&gt;stackSize )
        cout &lt;&lt; "Stack is full, you must POP an element before PUSHing a new one!" &lt;&lt; endl;
    else
    {
        this-&gt;elements[ (this-&gt;stackSize - 1) - this-&gt;storedElements ] = newElement;
        this-&gt;storedElements++;
    }
}

int myStaticIntStack::pop()
{
    if( this-&gt;storedElements == 0 )
    {
        cout &lt;&lt; "Stack is empty, you must PUSH an element before POPping one!" &lt;&lt; endl;
        return -1;
    }
    else
    {
        storedElements--;
        return this-&gt;elements[ (this-&gt;stackSize - 1) - this-&gt;storedElements ];
    }
}

int myStaticIntStack::peek()
{
    if( this-&gt;storedElements == 0 )
    {
        cout &lt;&lt; "Stack is empty, you must PUSH an element before PEEKing one!" &lt;&lt; endl;
        return -1;
    }
    else
    {
        return this-&gt;elements[ this-&gt;stackSize - this-&gt;storedElements ];
    }
}

int main()
{
    myStaticIntStack aStack(3);

    cout &lt;&lt; "Popped Element: " &lt;&lt; aStack.pop() &lt;&lt; endl;

    aStack.push(1);
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;
    aStack.push(2);
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;
    aStack.push(3);
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;
    aStack.push(4);
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;

    cout &lt;&lt; "Popped Element: " &lt;&lt; aStack.pop() &lt;&lt; endl;
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;
    cout &lt;&lt; "Popped Element: " &lt;&lt; aStack.pop() &lt;&lt; endl;
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;
    cout &lt;&lt; "Popped Element: " &lt;&lt; aStack.pop() &lt;&lt; endl;
    cout &lt;&lt; "Stack Top is: " &lt;&lt; aStack.peek() &lt;&lt; endl;

    return 0;
}


The code is compiling and running correctly, this is standard output:

Stack is empty, you must PUSH an element before POPping one! 
Popped Element: -1 
Stack Top is: 1 
Stack Top is: 2 
Stack Top is: 3 
Stack is full, you must POP an element before PUSHing a new one! 
Stack Top is: 3 
Popped Element: 3 
Stack Top is: 2 
Popped Element: 2 
Stack Top is: 1 
Popped Element: 1 
Stack is empty, you must PUSH an element before PEEKing one! 
Stack Top is: -1


However I was given a B due to the following reasons:


There was a better way of implementing it. 
I didn't manage well the case in which I'm trying to POP an element from an empty stack, since it's confusing that pop() returns a value even if Stack is empty.


Can you please help me understand how I could improve my code?


Question: Who invented pointers?
Answer: Pointers are really storage addressed by the contents of a register. As such all assembler languages implement this in some way, and, before that all hard coded machine code implemented this.

There will be some argument as to the first computer that implemented this. As far as I know the  Manchestern University Small Scale System was the first to include storage addressed by program controlled registers. It may have been preceded by the ENIAC system but it had so little storage as to make addressable storage a moot point.