12
Overloading
[over]
12.6
Overloaded operators
[over.oper]
12.6.5
Subscripting
[over.sub]
1
#
A
subscripting operator function
is a function named
operator
[
]
that is a non-static member function with exactly one parameter
.
For an expression of the form
postfix-expression
[
expr-or-braced-init-list
]
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
[
]
(
expr-or-braced-init-list
)
2
#
[
Example
1
:
struct
X
{
Z
operator
[
]
(
std
::
initializer_list
<
int
>
)
;
}
; X x; 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
—
end example
]