If "operator[]" is to be overloaded with a non-const version, const version shall also be implemented
If "operator[]" is to be overloaded with a non-const version, const version shall also be implemented.
Typically, you overload the subscript operator operator[] to provide
read and write access to individual elements of an array or similar structure contained in a
class. If you implement a non-const overload of
operator[], you must also implement a const version
of this overload. Otherwise, you cannot use operator[] to read elements
of a const object.
This rule allows the implementation of a const overload of
operator[] for read-only access without the corresponding
non-const overload.
Polyspace® flags the definition of the non-const member function if no
corresponding const version of the member function is implemented.
If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.
| Group: Overloading |
| Category: Required, Automated |