I've been asked in a class I'm taking to overload [] and return both a const and a non const character:
char * data_;
char & operator [] (size_t index);
const char & operator [] (size_t index) const;
I have the same implementation for both, and it compiles, but I'm pretty sure I'm missing something here:
const char & Array::operator [] (size_t index) const
{
return data_[index]; // todo: needs to be const?
}
How can I ensure the returned character is not modifiable?