Ask Your Question
3

What is the sequence of calling overloaded functions for the operator []?

asked 2021-08-28 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-08-01 07:00:00 +0000

david gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-28 11:00:00 +0000

Seen: 10 times

Last updated: Aug 01 '21