When an object is indexed using operator [], the overloaded function called depends on the type of the object being indexed. The sequence of calling overloaded functions for the operator [] is as follows:
If the object being indexed is an array or a pointer, the overloaded subscript operator [] specific to that data type is called.
If the object being indexed is a class object that has overloaded the subscript operator [], then that overloaded operator is called.
If the object being indexed is a class object and the overloaded subscript operator [] is not defined for that class, the compiler looks for a member function named operator[] within the class hierarchy.
If the operator [] is not defined for the object being indexed nor within the class hierarchy, a compiler error is generated.
Asked: 2021-08-28 11:00:00 +0000
Seen: 11 times
Last updated: Aug 01 '21