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关键字先声明呢? ...
随机推荐
- 【分块】hdu5057 Argestes and Sequence
分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...
- Problem X: 零起点学算法22——华氏摄氏温度转换
#include<stdio.h> int main() { float f,c; while(scanf("%f",&f)!=EOF) c=*(f-); pr ...
- Mapper动态代理开发
在开发的过程中只需要写Dao层的借口,无需写其实现类,实现类有框架自己补充. 框架是根据mapper文件自动补充的,因此需要满足下面四个条件 Mapper接口开发需要遵循以下规范: Mapper.xm ...
- golang技巧-接口型函数
接口型函数:指的是用函数实现接口,这样在调用的时候就会非常简便,这种函数为接口型函数,这种方式适用于只有一个函数的接口. 定义一个类型,这个类型只定义了函数的参数列表,函数参数列表与接口定义的方法一致 ...
- iis日志字段解析
IIS日志字段 #Software: Microsoft Internet Information Services 7.5 #Version: 1.0 #Date: 2013-08-21 01:00 ...
- Xcode编译错误和警告汇总
1.error: macro names must be identifiers YourProject_prefix.pch 原因: 因为你弄脏了预处理器宏,在它处于<Multiple Val ...
- Swift,函数
1.无参数无输出的函数 func a(){ print("HI") } a() //HI 2.有参数有输出的函数 func add(a:Int,b:Int)->Int{ // ...
- Coherence装载数据的研究-PreloadRequest
最近给客户准备培训,看到Coherence可以通过三种方式批量加载数据,分别是: Custom application InvocableMap - PreloadRequest Invocation ...
- dd-wrt端口映射不出去的解决办法
本人有一个巴法络的WZR-HP-G450H系统自带的固件不好用,但是随机却带了一个官方定制的DD-WRT,于是刷了去,但是今天在做一个FTP的时候突然无论怎么样映射或是做DMZ都不会出去,终于找到解决 ...
- 【Sofa】Sofa比赛成绩记录
最高得到过第4名,然后后面跌倒了第7名,现在追到了第6名.虽然名次还不是最高,但是很开心,今天能在一道一直困扰的题目上有突破,就是那个自行车预测的题目,开始过拟合了.后面进行了一些处理,效果很明显.继 ...