引用存储在堆还是堆栈上? [英] Are references stored on the heap or stack?

查看:463
本文介绍了引用存储在堆还是堆栈上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道代码中是否引用了诸如c之类的变量:

I wonder whether the reference variables such as c in this code:

int a = 5;
int & c = a;

是从堆或堆栈分配的. 有人可以帮忙吗?谢谢

are allocated from heap or stack. Can anyone help? Thanks

推荐答案

引用只是别名,并且C ++ 11标准未指定引用是否需要实际存储.

A reference is just an alias, and it is unspecified by the C++11 Standard whether it requires actual storage or not.

根据C ++ 11标准的第8.3.2/4段:

Per Paragraph 8.3.2/4 of the C++11 Standard:

尚不确定引用是否需要存储(3.7).

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

这篇关于引用存储在堆还是堆栈上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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