Instead of exposing the underlying array, you could have a length
method that returns EndIndex-StartIndex
, and an array operator that returns an item from the array offset by the value of the StartIndex
.
The you would access the items in the array like this:
for (int i = 0; i < obj.length(); i++) {
BusinessClass &item = obj[i];
}
The MyClass class would look something like this:
class MyClass {
public:
size_t length() const {
return EndIndex - StartIndex;
};
BusinessClass &operator[](size_t off) {
return myArray[StartIndex+off];
};
private:
BusinessClass myArray[MAX_COUNT];
int StartIndex; //start index
int EndIndex; //End index
};