gpt4 book ai didi

c++ - const T& rf = lvalue of T 是身份转换吗?

转载 作者:行者123 更新时间:2023-12-02 10:05:41 25 4
gpt4 key购买 nike

T t;
const T& rf = t; // #1

考虑初始化 #1如上所示。是身份转换吗?换句话说, rf直接绑定(bind)到初始化表达式?如果不是这样,#1 有多少标准转换,这些转换的名称是什么?

最佳答案

这是一种身份转换。 [over.ics.ref]/1 :

When a parameter of reference type binds directly to an argument expression, the implicit conversion sequence is the identity conversion, unless the argument expression has a type that is a derived class of the parameter type, in which case the implicit conversion sequence is a derived-to-base Conversion ([over.best.ics]). [...] If the parameter binds directly to the result of applying a conversion function to the argument expression, the implicit conversion sequence is a user-defined conversion sequence, with the second standard conversion sequence either an identity conversion or, if the conversion function returns an entity of a type that is a derived class of the parameter type, a derived-to-base Conversion.



(强调我的)

在您的情况下,参数类型与参数类型相同,因此参数类型既不是从参数类型派生的,也不需要用户定义的转换函数。

关于c++ - const T& rf = lvalue of T 是身份转换吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60300663/

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