5.2 Smart Pointer(智能指针)

shared_ptr的aliasing构造函数,接受一个shared pointer和一个raw pointer。它允许你掌握一个事实:某对象拥有另一个对象。例如:

struct X
{
int a;
}; shared_ptr<X> px(new X);
shared_ptr<int> pi(px,&px->a);

weak_ptr是shared-ptr的帮手,用来共享但不拥有对象,它的use_count()返回的对象是被shared_ptr拥有的次数,而且weak_ptr可以为空->expired()结果是true;lock()会产出一个shared-ptr。

class unique_ptr继承auto_ptr(现已不被认可),可以release()(shared-ptr不可以release是因为可能有其他shared-ptr指向它对象)。

对array,unique_ptr提供偏特化版本,而不用定义自己的deleter。例如:

std::unique_ptr<std::string[]> up(new std::string[10]);

unique_ptr与shared_ptr的deleter接口不同,它必须指明deleter的类型作为第二个template实参。

5.3 数值的极值

书中的例子用到 cout << boolalpha;

boolalpha,函数名称,功能是把bool值显示为true或false。

 

The C++ Standard Library --- A Tutorial Reference 读书笔记的更多相关文章

  1. 《The Python Standard Library》——http模块阅读笔记1

    官方文档:https://docs.python.org/3.5/library/http.html 偷个懒,截图如下: 即,http客户端编程一般用urllib.request库(主要用于“在这复杂 ...

  2. 《The Python Standard Library》——http模块阅读笔记3

    http.cookies — HTTP state management http.cookies模块定义了一系列类来抽象cookies这个概念,一个HTTP状态管理机制.该模块支持string-on ...

  3. 《The Python Standard Library》——http模块阅读笔记2

    http.server是用来构建HTTP服务器(web服务器)的模块,定义了许多相关的类. 创建及运行服务器的代码一般为: def run(server_class=HTTPServer, handl ...

  4. [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II

    [译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...

  5. [译]The Python Tutorial#10. Brief Tour of the Standard Library

    [译]The Python Tutorial#Brief Tour of the Standard Library 10.1 Operating System Interface os模块为与操作系统 ...

  6. Swift Standard Library Reference.pdf

    Swift Standard Library Reference.pdf 下载地址 http://download.csdn.net/detail/swifttrain/7446331 自己的Mark ...

  7. C++11新特性——The C++ standard library, 2nd Edition 笔记(一)

    前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...

  8. Python Standard Library

    Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...

  9. The Python Standard Library

    The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...

随机推荐

  1. OSG绘制几何图形

    在OSGMFC程序基础上修改OSG_MFC类的方法,如下: void cOSG::InitSceneGraph(void) { // Init the main Root Node/Group mRo ...

  2. MongoDB概念解析

    数据库 MongoDB默认把_id设置为主键(_开头的键是保留的) 数据库名必须为小写 RDBMS与MongoDB对应的术语比较 需注意 文档中的键/值对是有序的. 文档中的值不仅可以是在双引号里面的 ...

  3. Vue.2.0.5-表单控件绑定

    基础用法 你可以用 v-model 指令在表单控件元素上创建双向数据绑定.它会根据控件类型自动选取正确的方法来更新元素.尽管有些神奇,但 v-model 本质上不过是语法糖,它负责监听用户的输入事件以 ...

  4. jquery .on的使用

    1.7版本以上,开始使用.on绑定时间 给jquery动态产生的元素绑定事件不能使用普通的$("#fff").click(function(){alert("ok&quo ...

  5. Java常用锁机制简介

    在开发Java多线程应用程序中,各个线程之间由于要共享资源,必须用到锁机制.Java提供了多种多线程锁机制的实现方式,常见的有synchronized.ReentrantLock.Semaphore. ...

  6. Oracle官方文档在线查看

    1.9i Oracle官方文档在线查看 http://www.oracle.com/pls/db92/homepage 2.10g Oracle官方文档线查看 http://www.oracle.co ...

  7. Git_Commands

  8. Leetcode: Elimination Game

    There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number ...

  9. [转] java书籍(给Java程序猿们推荐一些值得一看的好书 + 7本免费的Java电子书和教程 )

    7本免费的Java电子书和教程 1. Thinking in Java (Third Edition) 本书的作者是Bruce Eckel,它一直都是Java最畅销的免费电子书.这本书可以帮助你系统的 ...

  10. [原创] 在spring 中使用quarts

    1.使用maven加载 quarts 的jar <dependency> <groupId>org.quartz-scheduler</groupId> <a ...