把《Effective C++》读薄
2015-09-19 20:25
399 查看
这本书很早就打算看了,但是一直没有开始。我觉得这本书其实只需要有一定C++经验,越早接触越好!
1
view c++ as a federation of languages应该看作C、STL、Templete、面对对象四个部分
prefer consts,enum,inline to #define
use const whenever possible
make sure the objects are initialized before they are used;
//这些都是初始化 int x=0; const char* a="abcde"; double d; cin>>d; Shit(string name,string address):name(name),address(address){} //Shit(stirng name,string address){this.name=name,this.address=address;}会先赋初值
2 Constructor,Destruction,and Assignment Operators
know what function C++ silently write and callsExplicitly disallow the use of complier-generated functions you do not want
Declare destructors virtual in polymophic base classe
Prevent exception from leaving destructors
Never call virtual function during construction or destruction
Have assignment operator return a reference to *this
Handle assignment to self in operator =
3 Resource Management
use object to manage resourcesthink carefully about copying behavior in resources manage classed
provide access to raw resources on resource-managing classedd
use the same form in corresponding use of new and delete
store new objects in smart pointers in standalone statements
4 Design and Declarations
make interfaces easy to use correctly and hard to use incorrectlytreat class design as type design
prefer pass-by-reference-to-const to pass-by-value
don’t try to return a reference when you must return an object
declare date member private
prefer non-member non-friend functions to member functions
declare non-member functions when type conversions should apply to all parameters
consider support for a non-throwing swap
相关文章推荐
- 设计模式C++达到 1.辛格尔顿
- C++利用模板实现一个队列
- C++ 空类默认产生的类成员函数
- C++多态性——函数的覆盖和隐藏
- Effective C++:条款14:在中小企业资源管理copying表现
- C++ Studio (二) ----- atoi()函数的实现 (自己编写功能)
- C++ Studio( 一 ) ----------- <stdlib.h> atoi() --------- 将string转换为int型
- C++捕捉关闭控制台应用程序事件
- 高效C++规划
- 【C语言】strlen的三种实现方法,strcmp,strcat,strcpy
- C++学习笔记(二)
- C++ 类成员函数作为参数
- C/C++中的一些区别
- Using GCC’s C++ Compiler
- C++ Primer Plus(第六版)--学习杂记(第六章)
- c语言中左移问题
- 默认参数使用技巧
- C++内存分配和拷贝构造函数写研究
- C语言关键字学习总结
- C++创建文件夹