effective c++ 学习笔记之 Shifting from c to c++
ABEntry::ABEntry(const std::string& name, const std::string& address,const std::list<PhoneNumber>& phones){theName = name; // these are all assignments,theAddress = address; // not initializationsthePhones = phonesnumTimesConsulted = 0;}
A better way to write the ABEntry constructor is to use the member initialization list instead of assignments:
ABEntry::ABEntry(const std::string& name, const std::string& address,const std::list<PhoneNumber>& phones): theName(name),theAddress(address), // these are now all initializationsthePhones(phones),numTimesConsulted(0){} // the ctor body is now empty sometimes must be used to initial. For example,data members that are const or are references
Here's the technique applied to both tfs and tempDir:
class FileSystem { ... }; // as beforeFileSystem& tfs() // this replaces the tfs object; it could be{ // static in the FileSystem classstatic FileSystem fs; // define and initialize a local static objectreturn fs; // return a reference to it}class Directory { ... }; // as beforeDirectory::Directory( params ) // as before, except references to tfs are{ // now to tfs()...std::size_t disks = tfs().numDisks();...}Directory& tempDir() // this replaces the tempDir object; it{ // could be static in the Directory classstatic Directory td; // define/initialize local static objectreturn td; // return reference to it}
effective c++ 学习笔记之 Shifting from c to c++相关推荐
- Effective C++ 学习笔记 第七章:模板与泛型编程
第一章见 Effective C++ 学习笔记 第一章:让自己习惯 C++ 第二章见 Effective C++ 学习笔记 第二章:构造.析构.赋值运算 第三章见 Effective C++ 学习笔记 ...
- Java:Effective java学习笔记之 考虑实现Comparable 接口
Java 考虑实现Comparable 接口 考虑实现Comparable 接口 1.Comparable接口 2.为什么要考虑实现Comparable接口 3.compareTo 方法的通用约定 4 ...
- Effective C++学习笔记(Part Five:Item 26-31)
2019独角兽企业重金招聘Python工程师标准>>> 最近终于把effectvie C++仔细的阅读了一边,很惊叹C++的威力与魅力.最近会把最近的读书心得与读书笔记记于此, ...
- Effective C++学习笔记(Part One:Item 1-4)
2019独角兽企业重金招聘Python工程师标准>>> 最近终于把effectvie C++仔细的阅读了一边,很惊叹C++的威力与魅力.最近会把最近的读书心得与读书笔记记于此,必备查 ...
- 【Effective C++ 学习笔记】
条款02:尽量以const,enum,inline替换 #define #define定义的常量也许从未被编译器看见,也许在编译器开始处理源码之前它就被预处理器移走了: #define不重视作用域,不 ...
- Effective C++ 学习笔记
基于此文档 http://wenku.baidu.com/view/ef989106e87101f69e3195db.html 条款13:以对象管理资源 目标:为确保资源被释放 1.获得资源后立即放进 ...
- Effective C++学习笔记——构造/析构/拷贝运算
条款9:决不再构造和析构过程中调用virtual函数,包括通过函数间接调用virtual函数. 应用:想在一个继承体系中,一个derived class被创建时,某个调用(例如生成相应的日志log)会 ...
- Effective C# 学习笔记(八)多用query语法,少用循环
对于C#的query查询语法,其可读性和可维护性要比原来的loop操作好得多 例子: 同样是创建个二维元组,并对其元组按到原点的距离进行倒序排序,用query 语法的表达形式要比原始的循环做法来的更易 ...
- Effective Java 学习笔记 1
Item 1: Consider static factory methods instead of constructors (多考虑使用静态工厂方法而不是构造方法) 使用静态工厂方法有以下几点好 ...
最新文章
- 2008 R2 AD通过组策略针对用户进行限制QQ等软件的运行
- 前阿里资深运营王殿进:SaaS产品经理所面临的苦恼
- mysql 主键 下一个值_INNODB自增主键的一些问题 vs mysql获得自增字段下一个值
- VS C++/ClI调用C++ 外部Dll无法查看变量值
- BZOJ2440 [中山市选2011]完全平方数
- 卸载sqlserver
- 在linux下安装iNode校园客户端
- 【读书笔记】深入浅出数据分析
- Unity 渲染管线总结
- Linux下Socket通信中非阻塞connect、select、recv 和 recvfrom、send和sendto大致讲解,附带非租塞connect代码、MSG_NOSIGNAL
- 磁敏感定量成像技术的基本方法和临床应用
- YQP36预加水盘式成球机设计(论文+DWG图纸)
- CATIA CAA二次开发专题(四)------创建自己的Addin
- PTA 古风排版 (20 分)含测试点
- 图片识别商品接口 API:天猫淘宝
- WiFi碰碰贴开发方案
- java性别分类汇总,excel表格 男女数据分开-Excel按性别进行分类汇总
- 在龙芯1C单片机上使用ESP8266 wifi透传模块
- win10家庭版新增策略组及关闭密码策略
- 高精度人员定位系统适用于哪些行业领域?
热门文章
- 彻底关闭苹果系统更新_彻底关闭iPhone自动更新系统 亲测有效
- linux jnlp显示异常,使用headless jnlp将slave连接到master时显示异常
- 一个简单的姓名拼音匹配
- PyTorch读取自己的本地图片数据集训练自编码器
- Latex参考文献插入
- java mycat reload_MyCAT 1.6 使用reload @@config_all报错
- 每日一题 笨拙的手指
- 表达式计算器 java代码_Java实现简单的表达式计算器功能示例
- uni-app开发h5 发布后背景图片找不到路径
- 六面体体积求解(规则不规则)