Why is std::basic_string::operator[] a const method if it's also a non-const method?
问题 http://cplusplus.com/reference/string/basic_string/operator[] I understand that it's advantageous to have a second version which returns const to prevent warnings when a const result is required and to mitigate casting but if the function already provides a non- const method (method-- not result) then what is the point of declaring the const -result method const ? 回答1: You need to understand, that the second ( const ) version not only returns a different result but is also marked itself as