1 There are certain rules when using references:    (Page 451)

A reference must be initialized when it is created. (Pointers can be initialized at any time.)

Once a reference is initialized to an object, it cannot be changed to refer to another object.  (Pointers can be pointed to another object at any time.)

You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.

2 References in functions     (Page 452)

When a reference is used as a function argument, any modification to the reference inside the function will cause changes to the argument outside the function.

3 Const references       (Page 453)

If you know the function will respect the constness of an object, making the arguement a const reference will allow the function to be used in all situations. For built-in types, the function will not modify the argument, and for user-defined types, the function will call only const member functions, and won't modify any public data members.

Temporary objects are always const, so if you donot use a const reference, that argument wonot be accepted by the compiler.

4 Argument-passing guidelines      (Page 455)

The efficiency savings can be substantial for such a simple habit: to pass an argument by value requires a constructor and destructor call, but if you are not going to modify the argument then passing by const refecence only needs an address pushed on the stack.

5 Copy-construction      (Page 463)

If you create a copy-construction, the compiler will not perform a bitcopy when creating a new object from an existing one. It always call your copy-constructor.

6 Temporary objects

7 Default copy-constructor

8 Alternatives to copy-construction

You need a copy-constructor only if you are going to pass an object of your class by value. If that never happens, you donot need a copy-constructor.

9 Preventing pass-by-value

There is a simple technique for preventing pass-by-value: declare a private copy-constructor. You donot even need to create  definition, unless one of your member functions or a friend function needs to perform a pass-by-value. If the user tries to pass or return the object by value, the compiler will produce an error message because the copy-constructor is private.

References & the Copy-Constructor的更多相关文章

  1. Copy Constructor in Java

    Reference: TutorialPoints, GeekforGeeks The copy constructor is a constructor which creates an objec ...

  2. Copy constructor vs assignment operator in C++

    Difficulty Level: Rookie Consider the following C++ program. 1 #include<iostream> 2 #include&l ...

  3. C++-copy constructor、copy-assignment operator、destructor

    本文由@呆代待殆原创,转载请注明出处. 对于一个类来说,我们把copy constructor.copy-assignment operator.move constructor.move-assig ...

  4. 构造函数语义学之Copy Constructor构建操作(2)

    二.详述条件 3 和 4 那么好,我又要问大家了,条件1 和 2比较容易理解.因为member object或 base class 含有copy constructor.那么member objec ...

  5. 构造函数语义学之Copy Constructor构建操作(1)

    一.Copy Constructor的构建操作 就像 default constructor 一样,如果class没有申明一个 copy constructor,就会隐含的声明或隐含的定义一个.生成的 ...

  6. no copy constructor available or copy constructor is declared &#39;explicit&#39;

    今天新写了一个类.然后对这个类使用STL中的vector,碰到错误: no copy constructor available or copy constructor is declared 'ex ...

  7. Copy Constructor的构造操作

    Copy Constructor的构造操作 有三种情况,会以一个object的内容作为另一个class object的初值: 1.  对一个object做显式的初始化操作 class X{…}; X ...

  8. Effective C++ 第0章 copy constructor和copy assignment operator

    拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...

  9. copy constructor

    copy constructor也分为trivial和nontrivial两种 如果class展现出bitwise copy semantics(按位拷贝语义),则不会构造出 copy constru ...

  10. c++官方文档-copy constructor

    #include <iostream> using namespace std; class Example5 { string* ptr; public: Example5(const ...

随机推荐

  1. hdu 01背包汇总(1171+2546+1864+2955。。。

    1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : ...

  2. 安卓问题http://blog.csdn.net/xb12369/article/details/50510302

  3. 【三支火把】---C指针总结

    好久没写博客了,重新学习C语言了的基础课程,发现很多东西都忘记的差不多了,闲来无事,总结一下关于指针的知识,希望能帮到像我一样的菜鸟们: 指针,众所周知是C语言的精华所在,不懂指针的话,你就不要说你学 ...

  4. Mac 解决SSH登录服务器终端乱码

    一.Mac自带的终端 ssh 连接Linux 乱码,可用如下方法解决 终端 --> 偏好设置 --> 描述文件 --> 高级  --> 设为GBK 即可 二.secureCRT ...

  5. 自己写的一个Js小插件

    这是效果图.上面一个过滤标签.下面弹出框,选择日,周,月.我的用途主要是报表查询的时候根据这3种类型来查询数据用的. 这里分享下代码. Js代码 (function ($) { $.extend($. ...

  6. 【转】Android平台下利用zxing实现二维码开发

    http://www.cnblogs.com/dolphin0520/p/3355728.html 现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描 ...

  7. socket编程——一个简单的样例

    从一个简单的使用TCP样例開始socket编程,其基本过程例如以下: server                                                  client ++ ...

  8. Android 软件开发之 PreferenceActivity 中的组件

    1.PreferenceActivity 介绍 PreferenceActivity 继承ListActivity 它是以一个列表的形式在展现内容,它最主要的特点是添加Preference可以让控件的 ...

  9. android87 Service

    ---------------------------------------------------------------------------- #Service(服务和Activity是运行 ...

  10. RHCA学习笔记:RH442-Unit9内核定时与进程延时

      Unit 9 Kernel Timing and Process Latency 内核定时与进程延时 学习目标: A.了解CPU 是怎样追踪时间的 B.调整CPU的访问次数 C.调整调度延时 D. ...