0
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

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by firstPerson
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.