class TextBlock {
pulic:
...
const char& operator[] (std:size_t position) const
{return text[position];}
char& operator[] (std:size_t position)
{return text[position];}
private:
std::string text;
};

for the member functions why the return type is reference to char char& instead of char?
return text[position] is a char for sure,not an address, is this contradictory?

Thanks

No since the return type is of char reference, that means you can
change the value while accessing it as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.