... elements
60       }
61
62       for (size_t i{0}; i < size; ++i) {
63          if (ptr[i] != right.ptr[i]) {
64             return false; // Array contents are not equal
65          }
66       }
67
68       return true; // Arrays are equal
69    }
70
71    // overloaded subscript operator for non-const Arrays;
72    // reference return creates a modifiable lvalue
73    int& Array::operator[](int subscript) {
74       // check for subscript out-of-range error
75       if (subscript < 0 || subscript >= size) {
76          throw out_of_range{"Subscript out of range"};
77       }
78
79       return ptr[subscript]; // reference return
80    }
81
82    // overloaded subscript operator for const Arrays
83    // const reference return creates an rvalue
84    int Array::operator[](int subscript) const {
85       // check for subscript out-of-range error
86       if (subscript < ...

Get C++ How to Program, 10/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.