12
Overloading
[over]
12.4
Overloaded operators
[over.oper]
12.4.5
Subscripting
[over.sub]
1
#
A
subscripting operator function
is a member function named
operator
[
]
with an arbitrary number of parameters
.
It may have default arguments
.
For an expression of the form
postfix-expression
[
expression-list
o
p
t
]
the operator function is selected by overload resolution (
[over.
match.
oper]
)
.
If a member function is selected, the expression is interpreted as
postfix-expression
.
operator
[
]
(
expression-list
o
p
t
)
2
#
[
Example
1
:
struct
X
{
Z
operator
[
]
(
std
::
initializer_list
<
int
>
)
; Z
operator
[
]
(
auto
.
.
.
)
;
}
; X x; x
[
{
1
,
2
,
3
}
]
=
7
;
// OK, meaning
x.
operator
[]({1,2,3})
x
[
1
,
2
,
3
]
=
7
;
// OK, meaning
x.
operator
[](1,2,3)
int
a
[
10
]
; a
[
{
1
,
2
,
3
}
]
=
7
;
// error: built-in subscript operator
a
[
1
,
2
,
3
]
=
7
;
// error: built-in subscript operator
—
end example
]