通常,解引用指针表达式的结果是否为引用类型? [英] Generally, is dereference pointer expression results a reference type?

查看:299
本文介绍了通常,解引用指针表达式的结果是否为引用类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

延迟指针导致间接使用对象的值.但是我从来没有真正理解过使用"是什么意思.我开始思考这个问题,直到我的编译器对以下代码产生错误

Deferencing pointer leads to using the value of the object indirectly. But I've never really understood what does the "using" means. I started to think the question until my compiler yield an error for the following code

int i = 0, *pi = &i;
decltype(*pi) c; // error: 'c' declared as reference but not initialized.

我很长时间以来一直在查看错误,并搜索了一些问题,我只能给出以下参数.我不知道它们是否正确.

I looked at the error for a very long time and searched some questions I can only give out the following arguments. I don't know if they are correct or not.

参数1:

1)*p是不是变量(或非变量表达式)的表达式

1) *p is an expression that is not a variable (or non-variable expression)

2)取消引用指针表达式会产生一个引用,实际上我们是在使用引用来访问对象的值

2) dereferencing pointer expression yields a reference, we are in fact using a reference to access the value of the object

参数2:

仅对decltype返回引用的解引用表达式,这不是一般情况

the dereferencing expression only for which decltype returns a reference, it is not a general case

请指出上述论点的任何不正确或不正确的描述.

Please points out any incorrectness or inaccurate descriptions of the above arguments.

推荐答案

取消对指针的引用会产生一个指向对象类型或对象的指向函数类型的左值表达式.它不会产生引用. * *pi是类型为.

Dereferencing a pointer yields an lvalue expression of the pointed-to type designating the object or function pointed to. It does not yield a reference.* *pi is an lvalue of type int.

decltype(此处不涉及例外)报告了表达式的 type 及其 value类别

decltype (with an exception not relevant here) reports both an expression's type and its value category, the latter being encoded with reference types. Since *pi is an lvalue, it's encoded as an lvalue reference type, so decltype(*pi) is int &: int for the type, & for the value category.

表达式永远不会具有引用类型,因为任何引用都会被调整分析" .

Expressions never have reference type because any referenceness is adjusted away "prior to any further analysis".

* 这不仅仅是技术上的区别:按照核心问题的方向232 核心问题453 ,您可以编写有效的取消引用表达式,将其结果绑定到引用会导致不确定的行为.

* This isn't a merely technical distinction: per the direction of core issue 232 and core issue 453, there are valid dereference expressions you can write where binding its result to a reference would cause undefined behavior.

这篇关于通常,解引用指针表达式的结果是否为引用类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆