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 ?的更多相关文章

  1. DNS重绑定DNS Rebinding攻击

    DNS重绑定DNS Rebinding攻击 在网页浏览过程中,用户在地址栏中输入包含域名的网址.浏览器通过DNS服务器将域名解析为IP地址,然后向对应的IP地址请求资源,最后展现给用户.而对于域名所有 ...

  2. 【SEED Labs】DNS Rebinding Attack Lab

    Lab Overview 实验环境下载:https://seedsecuritylabs.org/Labs_16.04/Networking/DNS_Rebinding/ 在这个实验中模拟的物联网设备 ...

  3. DNS Rebinding漏洞原理

    目录 SSRF过滤器设计 背景知识 DNS TTL 公网DNS服务器 DNS重绑定 自建DNS服务器 利用步骤图解 实战中的注意事项 防御 参考 DNS Rebinding 广泛用于绕过同源策略.SS ...

  4. cx_Oracle摘记

    由于想使用python操作oracle所以查看了cx_Oracle的官方文档,同时也查看了twisted中cx_Oracle的使用.下面是摘自文档中一些我认为有用的内容 cx_Oracle is a ...

  5. word20161218

    QoS, Quality of Service / 服务质量 QoS Admission Control Service / QoS 许可控制服务 Quality of Service, QoS / ...

  6. 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 ...

  7. iOS为真机调试增加scribble来定位野指针

    尽管在ARC中,野指针出现的频率已经大大降低了,但是仍然会有野指针困扰着我们. 在模拟器调试中,我们可以开启scribble或者zombieObject来将已经释放的内存填充无意义的内容,能够将一些非 ...

  8. jquery-jsrender使用

      JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...

  9. 【python】为什么修改全局的dict变量不用global关键字

    转自:http://my.oschina.net/leejun2005/blog/145911?fromerr=qnPCgI19#OSC_h4_8 为什么修改字典d的值不用global关键字先声明呢? ...

随机推荐

  1. 【树状数组】bzoj2743 [HEOI2012]采花

    http://www.cnblogs.com/proverbs/archive/2012/10/29/2745281.html (↑)这样处理之后,每次询问时,对于每种颜色,从1到其倒数第二次出现的位 ...

  2. 《深入理解Spark-核心思想与源码分析》(二)第二章Spark设计理念和基本架构

    若夫乘天地之正,而御六气之辩解,以游无穷者,彼且恶乎待哉? ——<庄子.逍遥游> 翻译:至于遵循宇宙万物的规律,把握“六气”的变化,遨游于无穷无尽的境域,他还仰赖什么呢! 2.1 初始Sp ...

  3. MySQL Workbench 工具

    http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html http://www.cnblogs.com/daimage/archive ...

  4. javascript 定时器 笔记

    最近想看下定时器,发现这东西越看越牵连的东西越多,比如js单线程,EVent loop 什么的 看到了几篇比较好的文章 http://ejohn.org/blog/how-javascript-tim ...

  5. Centos7下ZABBIX安装全记录

    安装之前务必关闭SELINUX Install Repository with MySQL database : rpm -i https://repo.zabbix.com/zabbix/3.4/r ...

  6. firefox dispatchevent的问题

    <!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8&qu ...

  7. ylbtech-LanguageSamples-AnonymousDelegates(匿名委托)

    ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-AnonymousDelegates(匿名委托) 1.A,示例(Sample) 返回顶部 ...

  8. javascript快速入门23--XHR—XMLHttpRequest对象

    创建XMLHttpRequest对象 与之前众多DOM操作一样,创建XHR对象也具有兼容性问题:IE6及之前的版本使用ActiveXObject,IE7之后及其它浏览器使用XMLHttpRequest ...

  9. shell--管道命令(pipe)

    管道命令使用的是“|”这个界定符号 管道命令“|”仅能处理经由前面一个命令传来的正确信息,也就是standard output的信息,对于standard error并没有直接处理的能力 每个管道后面 ...

  10. Android手掌抑制功能的实现

    近期须要实现一个功能,在Activity中有一个手写区域,为了更好的用户体验,须要满足即使整个手掌放在屏幕上时(android平板,屏幕比較大)也仅仅响应手写区域内的操作,即在支持多点触控的情况下,仅 ...