/* * stack.cpp * * Created on: Apr 2, 2014 * Author: carola */ #include using namespace std; #define DEFAULT_CAPACITY 50 template class Stack { int top; T* storage; public: Stack(); Stack(int capacity); ~Stack(); void push(T x); T pop(); }; template Stack::Stack() { storage = new T[DEFAULT_CAPACITY]; top=0; // top points to first empty slot } template Stack::Stack(int capacity) { storage = new T[capacity]; top=0; // top points to first empty slot } template Stack::~Stack() { delete []storage; } template void Stack::push(T x) { storage[top++]=x; // Assume there is enough capacity } template T Stack::pop() { return storage[--top]; } struct point{ double x; double y; }; int main(){ Stack dstack; //calls default constructor dstack.push(4.5); dstack.push(3.3); Stack* intstack = new Stack(); intstack->push(5); int a = intstack->pop(); //a = (*intstack).pop(); cout<<"Popped: "< pstack; struct point p = {4.0,2.0}; pstack.push(p); return 0; }