I have a class which contains an array and there are setter and getter functions to change/return the elements of this array.
I have two queries:
1. Is it a good design practice for these setters and getters to be responsible for bounds checking? Or should this be left to calling program?
2. For the getter function (the input being a pos of the array) how would you notify the calling function that pos is not within bounds? You can't return -1 because the array could contain negative numbers. I thin std::string throws an exception but unfortunately I'm writing on a platform where this isn't possible.
1. Both std::vector and std::string have two [gs]etters: the at() and the op[]. One throws, the other might not. The one throwing obviously must check bounds. The other?