gpt4 book ai didi

c++ - 左值如何转换为右值

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:55 26 4
gpt4 key购买 nike

int x = 8;
int y = x ;

这里左值如何充当右值?我知道这是一个愚蠢的问题,但我只想阐明我对右值和左值的概念。

最佳答案

通过左值右值的转换。

您几乎可以在任何需要右值 和隐式左值右值 转换的地方使用左值将自动发生。

非正式地,此转换是“评估”或“获取”左值 所指对象的值。并非在所有情况下都严格如此。在未评估的上下文中,例如 sizeof 的操作数,将不会使用对象的值。

ISO/IEC 14882:2011 4.1 [conv.lval]:

A glvalue (3.10) of a non-function, non-array type T can be converted to a prvalue. If T is an incomplete type, a program that necessitates this conversion is ill-formed. If the object to which the glvalue refers is not an object of type T and is not an object of a type derived from T, or if the object is uninitialized, a program that necessitates this conversion has undefined behavior. If T is a non-class type, the type of the prvalue is the cv-unqualified version of T. Otherwise, the type of the prvalue is T.

关于c++ - 左值如何转换为右值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14024639/

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