gpt4 book ai didi

c++ - 为什么函数的返回值不是符号名称的一部分

转载 作者:太空宇宙 更新时间:2023-11-04 16:01:29 27 4
gpt4 key购买 nike

返回类型不是符号名称的一部分。这使得基于返回类型的函数重载变得不可能。这种方法背后的想法是什么?

最佳答案

Bjarne Stroustrup 在 comp.lang.c++ 新闻组 1998 年 1 月 12 日的帖子中给出的原因是

The reason that C++ doesn't allow overload resolution based on a return type (so that you need to use explicit qualification in the examples below) is that I wanted overload resolution to be bottom up. For example, you can determine the meaning of a subexpression a+b without considering the complete expression that a+b is part of. Overload resolution can be subtle so even though I knew how to use return types as part of resolution (Ada showed how), I decided not to. As a result of this decision, a+b means the same in a+b+c as in a+b+d.

同意与否,这是设计决策背后的基本原理。

关于c++ - 为什么函数的返回值不是符号名称的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43069825/

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