gpt4 book ai didi

c++ - cpp 运算符重载操作数位置 [] vs ==

转载 作者:行者123 更新时间:2023-11-27 22:37:22 25 4
gpt4 key购买 nike

char& operator[]bool operator== 有何不同?一个将操作数放在 [] 之间,而另一个将操作数放在 == 之后。它怎么知道把操作数放在哪里?左括号和右括号有什么特别的技巧吗?

最佳答案

How does it know where to put the operand?

嗯。因为标准是这么说的?

§11.5.5 Subscripting [over.sub]/1 :

operator[] shall be a non-static member function with exactly one parameter. It implements the subscripting syntax

postfix-expression [ expr-or-braced-init-list ]

Thus, a subscripting expression x[y] is interpreted as x.operator[](y) for a class object x of type T if T​::​operator[](T1) exists and if the operator is selected as the best match function by the overload resolution mechanism ([over.match.best]).

关于c++ - cpp 运算符重载操作数位置 [] vs ==,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52565857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com