... 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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.