Array1.h
上传用户:okapple
上传日期:2021-05-13
资源大小:3k
文件大小:1k
源码类别:

压缩解压

开发平台:

C/C++

  1. // Fig. 8.4: array1.h
  2. // Simple class Array (for integers)
  3. #ifndef ARRAY1_H
  4. #define ARRAY1_H
  5. #include <iostream.h>
  6. class Array {
  7.    friend ostream &operator<<( ostream &, const Array & );
  8.    friend istream &operator>>( istream &, Array & );
  9. public:
  10.    Array( int = 10 );                   // default constructor
  11.    Array( const Array & );              // copy constructor
  12.    ~Array();                            // destructor
  13.    int getSize() const;                 // return size
  14.    const Array &operator=( const Array & ); // assign arrays
  15.    bool operator==( const Array & ) const;  // compare equal
  16.    // Determine if two arrays are not equal and
  17.    // return true, otherwise return false (uses operator==).
  18.    bool operator!=( const Array &right ) const  
  19.       { return ! ( *this == right ); }
  20.    
  21.    int &operator[]( int );              // subscript operator
  22.    const int &operator[]( int ) const;  // subscript operator
  23.    static int getArrayCount();          // Return count of 
  24.                                         // arrays instantiated.
  25. private:
  26.    int size; // size of the array
  27.    int *ptr; // pointer to first element of array
  28.    static int arrayCount;  // # of Arrays instantiated
  29. };
  30. #endif