// @topic S-0314-09-03-30 C++ template class demo II // @brief template class Stack // Stack.h #ifndef STACK_H_INCLUDED_ #define STACK_H_INCLUDED_ #include <string> #include "Storage.h" // C++ template sample template< typename ValueType > class Stack { unsigned int sp; static const unsigned int DEFAULT_STORAGE_SIZE = 1; static const unsigned int STORAGE_GROW_FACTOR = 2; friend void print_stack( Stack< ValueType > st ); Storage< ValueType > storage; public: // constructor Stack() : sp( 0 ), storage( DEFAULT_STORAGE_SIZE ) { } void push( ValueType value ) { if ( storage.size() <= sp ) { storage.reallocate( STORAGE_GROW_FACTOR ); } storage.store( value, sp ); ++sp; } void pop() { --sp; } ValueType top() { return storage.get( sp - 1 ); } unsigned int size() { return sp; } };//class Stack // an attempt to specialize Stack for strings ( unfinished...) template<> class Stack< std::string > { //... };//class Stack void print_stack( Stack< int > st ); #endif //STACK_H_INCLUDED_