Looking at your code, it seems to be that there are a couple of odd things going on. They may not be related to your problem though. Below is what I think you are trying to do (correct me if I am wrong) and why I think it is inappropriate:
1. You have a variable m_iGFactor that determines how much the stack grows by when pushing something onto the stack nessicitates a memory reallocation. The variable m_iMultiple stores how many m_iGFactors were allocated at last resize. You therefore calculate the maximum size of the stack with m_iGFactor * m_iMultiple. This is fine although strickly speaking m_iMultiple is not needed. The problem comes from the way you find where the top of the stack is (see 2).
2. You are assigning NULL to array elements to indicate that that portion of the stack is empty. You iterate back or forward over the array to find the first NULL element for pushing and last non-NULL element for popping, resizing if needed. The problem with this is two fold. Your array elements are
not a pointer type but are doubles. In effect you store zero to indicate unused space, but what if you actually wanted to push zero onto the stack? Also, when you test if an array element is NULL, any non-zero value greater than zero but less than one (e.g 0.9) will also appear to be NULL since NULL is defined as 0 and the mantissa of the floating point number will be discarded for comparison. The second problem is that it is inefficient. You just need to store the top of the stack as an index into the array.
This is how I would change your code:
// CStack class#include <iostream>using namespace std;class CStack {public: // Constructors CStack(unsigned int iGFactor = 3); CStack(CStack const &obj); ~CStack(void); // Operators CStack& operator =(CStack const &rRHArg); CStack& operator +=(double const value); // Methods CStack& Push(double const value); double Pop(void); void Clear(void); unsigned int Size(void); unsigned int Capacity(void); private: double* m_Array; unsigned int m_iGFactor; unsigned int m_iMultiple; unsigned int stackTop; protected: double* ResizeArray(void);};CStack::CStack(unsigned int const iGFactor):m_iGFactor(iGFactor), m_iMultiple(2){ if(iGFactor==0) throw("Invalid growth factor!"); m_Array = new double[iGFactor]; stackTop = 0; for(int i=0; i<iGFactor; i++) m_Array = 0.0;}CStack::CStack(CStack const &obj):m_iGFactor(obj.m_iGFactor), m_iMultiple(obj.m_iMultiple), stackTop(obj.stackTop){ m_Array = new double[m_iGFactor*m_iMultiple]; for(unsigned int i=0; i <= stackTop; i++) m_Array = obj.m_Array;}CStack::~CStack(void){ delete [] m_Array;}CStack& CStack::operator =(CStack const &rRHArg){ // for the expression a = b, a will be *this, and b will be rRHArg if (&rRHArg != this) // check for self assignment { delete [] m_Array; m_iGFactor = rRHArg.m_iGFactor; m_iMultiple = rRHArg.m_iMultiple; stackTop = rRHArg.stackTop; m_Array = new double[m_iGFactor*m_iMultiple]; for(unsigned int i=0; i < stackTop; i++) m_Array = rRHArg.m_Array; } return *this; //allows chaining of the = operator}CStack& CStack::Push(double const value){ if (stackTop == (m_iMultiple * m_iGFactor) - 1) { m_iMultiple++; m_Array = ResizeArray(); } m_Array[stackTop] = value; stackTop++; return *this;}double* CStack::ResizeArray(){ double* NewArray = new double[m_iGFactor*m_iMultiple]; for(unsigned int i=0; i<(m_iGFactor*m_iMultiple); i++) NewArray = m_Array; delete [] m_Array; return NewArray;}CStack& CStack::operator +=(double const value){ this->Push(value); return *this;}double CStack::Pop(){ if(stackTop <= 0) throw("Stack is empty!"); stackTop--; if (stackTop < (m_iGFactor*m_iMultiple) - m_iGFactor) { m_iMultiple--; m_Array = ResizeArray(); } return m_Array[stackTop];}void CStack::Clear(){ m_iMultiple = 1; m_Array = ResizeArray(); stackTop = 0; return;}unsigned int CStack::Size(){ return stackTop;}unsigned int CStack::Capacity(){ return (m_iGFactor*m_iMultiple);}