c++ why doesn't c++ allow rebinding a reference ?
1. The primary reason that the designer of C++ introduced reference into the language is to support "encapsulated" address passing (to or from a function).
C++ Primer 4th Edition Section 2.5:
In real-world programs, references are primarily used as formal parameters to functions.
If you're planning to return a reference from a function, you must be sure it's "safe" to do so. See C++ Primer 4th Edition Section 7.3.2 Subsection "Returning a Reference"
2. Another reason is the syntax. In Java, assignning to a reference always means "rebind this reference so it points to another object" (which is exactly the same meaning as you assign to a pointer in C++), note that in Java, primitive types don't have references, however in C++, primitive types can also have references, and assigning to a reference of a primitive type means "assign the value of the object on the right side of the = operator to the object pointed by the reference on the left side of the = operator", this meaning also applies on class-type objects. When you're aware of this fact, it's easy to see that if you want to "rebind" a reference to another object, you'll have to invent a new operator (if you still use the operator "=", how would the compiler know whether you're assigning value or rebinding a reference?) to stand for the "rebind" operation, which is unnecessary because you can just use pointers instead.
In short.
1. Reference is just designed to support glorified "address passing", primarily used as parameters and/or return values. Not to replace pointers.
2. Because pointers can "rebind", so we don't need the same thing twice.
c++ why doesn't c++ allow rebinding a reference ?的更多相关文章
- DNS重绑定DNS Rebinding攻击
DNS重绑定DNS Rebinding攻击 在网页浏览过程中,用户在地址栏中输入包含域名的网址.浏览器通过DNS服务器将域名解析为IP地址,然后向对应的IP地址请求资源,最后展现给用户.而对于域名所有 ...
- 【SEED Labs】DNS Rebinding Attack Lab
Lab Overview 实验环境下载:https://seedsecuritylabs.org/Labs_16.04/Networking/DNS_Rebinding/ 在这个实验中模拟的物联网设备 ...
- DNS Rebinding漏洞原理
目录 SSRF过滤器设计 背景知识 DNS TTL 公网DNS服务器 DNS重绑定 自建DNS服务器 利用步骤图解 实战中的注意事项 防御 参考 DNS Rebinding 广泛用于绕过同源策略.SS ...
- cx_Oracle摘记
由于想使用python操作oracle所以查看了cx_Oracle的官方文档,同时也查看了twisted中cx_Oracle的使用.下面是摘自文档中一些我认为有用的内容 cx_Oracle is a ...
- word20161218
QoS, Quality of Service / 服务质量 QoS Admission Control Service / QoS 许可控制服务 Quality of Service, QoS / ...
- Default Parameter Values in Python
Python’s handling of default parameter values is one of a few things that tends to trip up most new ...
- iOS为真机调试增加scribble来定位野指针
尽管在ARC中,野指针出现的频率已经大大降低了,但是仍然会有野指针困扰着我们. 在模拟器调试中,我们可以开启scribble或者zombieObject来将已经释放的内存填充无意义的内容,能够将一些非 ...
- jquery-jsrender使用
JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...
- 【python】为什么修改全局的dict变量不用global关键字
转自:http://my.oschina.net/leejun2005/blog/145911?fromerr=qnPCgI19#OSC_h4_8 为什么修改字典d的值不用global关键字先声明呢? ...
随机推荐
- MathType如何插入竖直线
不用键盘上的竖线,用左竖直线和右竖直线.
- 玩转JavaScript正则表达式
Why Regular Expression 我们先来看看,我们干哈要学正则表达式这玩意儿: 复杂的字符串搜寻.替换工作,无法用简单的方式(类似借助标准库函数)达成. 能够帮助你进行各种字符串验证. ...
- getopt使用
参考: http://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html http://en.wikipedia.org ...
- webpack 打包压缩 ES6文件报错UglifyJs + Unexpected token punc «(», expected punc
- [Git] 关于refs/for/ 和refs/heads/
转载自: http://lishicongli.blog.163.com/blog/static/146825902013213439500/ 1. 这个不是git的规则,而是gerrit的规 ...
- MyEclipse中快捷键
------------------------------------- MyEclipse 快捷键1(CTRL) ------------------------------------- Ctr ...
- 正则表达式表示 ja.resx 所在行
[^\n]*ja.resx[^\n]*\n?正则表达式表示 ja.resx 所在行 用ultraEdit 删除关键字所在行的下一行或是上一行,所在行保留 删除 关键字所在行 的前3行: (^.*?(\ ...
- docker入门——镜像简介
什么是docker镜像 Docker镜像是由文件系统叠加而成. 最底端是一个引导文件系统,即bootfs: 这很像典型的Linux/Unix的引导文件系统.Docker用户几乎永远不会和引导文件系统有 ...
- 【Java】Java_06 基本数据类型
1.基本数据类型 Java是一种强类型语言,每个变量都必须声明其类型. . Java的数据类型分为两大类:基本类型(primitive type)和引用类型 (reference type) ...
- JAVA IO操作:数据操作流:DataOutputStream和DataInputStream
掌握DataOutputStream和DataInputStream的作用. 可以使用DataOutputStream和DataInputStream写入和读取数据. 在IO包中提供了两个与平台无关的 ...