gpt4 book ai didi

c++ - 为什么不能在 C++ 中重载所有内容?

转载 作者:IT老高 更新时间:2023-10-28 21:40:34 26 4
gpt4 key购买 nike

sizeoftypeid不能重载是有道理的,但是我看不出重载的危害?:,.*.。这有技术原因吗?

最佳答案

引用 Bjarne Stroustrup 的话:

There is no fundamental reason to disallow overloading of ?:. I just didn't see the need to introduce the special case of overloading a ternary operator. Note that a function overloading expr1?expr2:expr3 would not be able to guarantee that only one of expr2 and expr3 was executed.

...

Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by . ... This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best.

Source

关于c++ - 为什么不能在 C++ 中重载所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5315908/

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