c ++中引用变量的大小 [英] size of reference variable in c++

查看:190
本文介绍了c ++中引用变量的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么这个问题没有讨论堆栈溢出?
引用只是变量的另一个名称,因此如何在内存级别执行



是作为指针实现的引用?

解决方案

引用如何实现纯粹是一个实现细节。但是是的,大多数实现都会使用指针来实现它们。

sizeof 运算符应用于引用,给出它所引用的元素的大小。 p>


引用本身的大小是多少?


C + 11标准:§8.3.2.4


不需要记录它如何实现引用。你也不应该认为实现是任何具体的。简而言之,语言标准将引用实现视为该语言的用户不需要知道的细节,因此它抽象这个细节。


I was wondering why this question wasn't discussed in stack overflow? reference is just an other name to variable so how does execution happen at memory level

are references implemented as pointers inside?

解决方案

How references are implemented is purely an implementation detail. But Yes, most implementations would implement them using pointers.
sizeof operator applied on an reference gives you the size of the element it referes to.

What is the size of the reference itself?

C+11 Standard: § 8.3.2.4

It is unspecified whether or not a reference requires storage (3.7).

Note that, Unspecified means that an compiler implementation does not need to document how it implements a reference. Neither should you consider the implementation to be anything specific. In short, the language standard treats reference implementation as an detail which user of the language does not need to know and hence it abstracts this detail.

这篇关于c ++中引用变量的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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