home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / compiler / sample07 / method2 / dll / stk.h < prev   
Encoding:
C/C++ Source or Header  |  1996-02-20  |  1.1 KB  |  63 lines

  1. /*****************************/
  2. /* STACK TEMPLATE DEFINITION */
  3. /* Template usage : Method 2 */
  4. /*****************************/
  5. #ifndef _STACK_TPL_H
  6.    #define _STACK_TPL_H
  7.  
  8. #if __DLL__
  9. #define IMPORT 
  10. #else
  11. #define IMPORT _Import 
  12. #endif
  13.  
  14.  
  15.    template<class T>
  16.    class stack
  17.       {
  18.       private:
  19.            T*   v;
  20.            T*   p;
  21.            int sz;
  22.       public:
  23.            static int IMPORT numberOfStack;
  24.            stack( int );
  25.            ~stack();
  26.            void push( T );
  27.            T pop();
  28.       };
  29.  
  30. /***************************************/
  31. /* Stack template implementation       */
  32. /***************************************/
  33.  
  34. #if __DLL__
  35. template<class T> int stack<T>::numberOfStack = 0  ;
  36. #endif
  37.  
  38.  
  39. template<class T>stack<T>::stack(int s)
  40.    {
  41.    ++stack<T>::numberOfStack ;
  42.    v = p = new T[sz=s];
  43.    }
  44.  
  45. template<class T>stack<T>::~stack()
  46.    {
  47.    delete [] v;
  48.    }
  49.  
  50.  
  51. template<class T> void stack<T>::push(T a)
  52.    {
  53.    *p++ = a ;
  54.    }
  55.  
  56. template<class T> T stack<T>::pop ()
  57.    {
  58.    return *(--p) ;
  59.    }
  60.  
  61. #endif
  62.  
  63.