gpt4 book ai didi

c++ - 使用好友功能进行Operator []重载

转载 作者:行者123 更新时间:2023-12-02 10:08:42 28 4
gpt4 key购买 nike

为什么不能将下标运算符(operator [])作为 friend 函数重载?

最佳答案

正如Bjarne Stroustrup在D&E book中所说:

However, even in the original design of C++, I restricted operators [], (), and -> to be members. It seemed a harmless restriction that eliminated the possibility of some obscure errors because these operators invariably depend on and typically modify the state of their left-hand operand. However, it is probably a case of unnecessary nannyism.

关于c++ - 使用好友功能进行Operator []重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42630761/

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