home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / friend.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  830 b   |  51 lines

  1. // "Friend Classes" -- FRIEND.HPP
  2. // This program illustrates friend classes
  3.  
  4. #include <iostream.h>
  5.  
  6. enum boolean { bFalse, bTrue };
  7.  
  8. class Array
  9. {
  10.   friend class fixedStack;
  11.  
  12.   public:
  13.     Array();
  14.     ~Array();
  15.  
  16.     void create(unsigned ArrSize);
  17.     
  18.     boolean insert(char x);
  19.     boolean remove(char& x);
  20.     
  21.     void erase();
  22.  
  23.   protected:
  24.     unsigned m_nWorkSize;
  25.     unsigned m_nArrSize;
  26.     char* m_pData;
  27. };
  28.  
  29. class fixedStack         // the class Array has befriended
  30. {
  31.  
  32.   public:
  33.     fixedStack(unsigned MaxSize = 10);
  34.     ~fixedStack();
  35.  
  36.     boolean isempty();
  37.  
  38.     void push(char x)
  39.       { m_pArr->insert(x); }
  40.     boolean pop(char& x)
  41.       { return m_pArr->remove(x); }
  42.     void clear()
  43.       { m_pArr->m_nWorkSize = 0; }
  44.  
  45.   protected:
  46.  
  47.     Array* m_pArr;
  48. };
  49.  
  50.  
  51.