I was reading this book called "Effective C++ Third Edition 55 Specific Ways to Improve", and while reading it I came across the topic of constness , i don't get the difference between the overloaded const operator[] which has bitwise and member function constness,
const char operator[](size_t t)
const{
return text[t];
}
, and the overloaded non-const [] which doesnt have to do anything with constants
char operator[](size_t t)
{
return text[t];
}
I have tried doing some operations with and without the const and non-const overloaded[] , but still haven't seen a difference , is this is used only to make the code readable ? or if there is any difference then what is it ?
This is my String class
class String
{
int len = 0;
char text[];
public :
String( const char c[])
{
strcpy(text , c);
len = strlen(text);
}
int length();
const char operator[](size_t t)
const{
return text[t];
}
char operator[](size_t t)
{
return text[t];
}
};