Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

  1. If the object being indexed is an array or a pointer, the overloaded subscript operator [] specific to that data type is called.

  2. If the object being indexed is a class object that has overloaded the subscript operator [], then that overloaded operator is called.

  3. 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.

  4. If the operator [] is not defined for the object being indexed nor within the class hierarchy, a compiler error is generated.