home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_11 / pugh / pedcon.hpp
C/C++ Source or Header  |  1993-09-08  |  816b  |  41 lines

  1. class CBase
  2.     {
  3. public:
  4.     CBase() { m_n=0;}
  5.     virtual ~CBase() { } ;
  6.     void SetN(int n)  {m_n = n;}
  7.     int GetN() {return m_n;}
  8.  
  9.     CBase operator-(const CBase & base) const;
  10.     const CBase & operator+=(int n);
  11.     const CBase & operator-=(int n);
  12.     const CBase & operator++(); //prefix ++ operator
  13.     CBase operator++(int);      //postfix ++ operator
  14.     int operator==(const CBase& base) const;
  15. private:
  16.     int m_n;
  17.     };
  18.  
  19. class CDerived : public CBase
  20.     {
  21. public:
  22.     CDerived() {};
  23.     const CDerived& operator=(const CDerived& derived);
  24.     };
  25.  
  26. void main()
  27.     {
  28.     CBase b1, b2;
  29.     CDerived d1, d2;
  30.  
  31.     b1.SetN(5);
  32.     b2.SetN(10);
  33.     d1.SetN(7);
  34.     d2.SetN(12);
  35.                         
  36.     CBase b3;
  37.  
  38.     CDerived d3;
  39.     d3 = d2 - d1;   
  40.     }
  41.