#include #include #include template class CStack { public: static enum {CStack_StackEmpty, CStack_BadMemory}; unsigned int size() { return StackSize; } bool empty() { return StackSize == 0; } T pop() { T top = 0; if(StackSize != 0) { top = _Stack[StackSize-1]; T* _newstack = (T*)malloc(--StackSize * sizeof(T)); if(_newstack == NULL) { throw (int)CStack_BadMemory; } for(int i=0;i s; for(int i=0;i<=10;i++) { s.push(i*i); } try { for(int i=0;i<=100;i++) { printf("%d\n",s.pop()); } } catch(int ex) { printf(ex == static_cast(CStack::CStack_StackEmpty) ? "Stack is empty" : "Can not alloc memory"); } getchar(); return 0; }