Hi, I am altering a vector class to take in custom index ranges, like [-5, 5] and [10, 20]. My teacher wants us to have a "myZero" variable that points to where the 0th element is or would be. But if I do this
customvector <int> example(1, 5);
where the parameters are the index boundaries, how can I have a pointer pointing to the 0th element if the space was not allocated? I am just conceptually lost on how to do this. Thanks.
You're probably supposed to have it point to the first element of the allocated array.
Hard to say without seeing the full task description.
It's possible to do arbitary pointer arithmetic, e.g.: int* myZero=newint-1;
While this compiles, it's undefined behavior and therefore incorrect, so I hope that's not what your teacher was expecting.
Ah. Yes, you can reach that by pointer arithmetic: int* myZero=myList-myLower;
However, doing that is not safe - it's okay to have a pointer exactly one element past the end of an array (so to -4 in this case), but everything beyond that is not allowed.
Ok, I see that myZero will be myList - myLower. How can I use myZero when overloading the  operator? My teacher says we can't just calculate the myZero index to the myList index using an integer everytime we use the subscript operator and that we have to use myZero.