内部如何实现引用? [英] How is reference implemented internally?

查看:85
本文介绍了内部如何实现引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道它是如何实现跨不同的编译器和调试/发行配置。标准是否对其实施提出了建议?

Just wonder how is it implemented actually across different compilers and debug/release configurations. Does standard somehow provides recommendations on its implementation? Does it differ anywhere?

我试图运行一个简单的程序,我已经从函数返回非const引用和指向局部变量的指针,但它的工作方式是一样的。所以是真的,内部引用只是一个指针?

I tried to run a simple program where i have been returning non-const references and pointers to local variables from functions but it worked out the same way. So is it true that reference internally is just a pointer?

推荐答案

引用的自然实现确实是一个指针。但是,在您的代码中不要依赖于此。

The natural implementation of a reference is indeed a pointer. However, do not depend on this in your code.

这篇关于内部如何实现引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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