<<Exceptional C++>> notes
-
class Complex
{
public:
explicit Complex(double real, double imaginary = )
: real_(real), imaginary_(imaginary)
{
} Complex& operaor+=(const Complex& o)
{
real_ += o._real_;
imaginary_ += o.imaginary_;
return *this;
} Complex& operator++()
{
++real_;
return *this;
} const Complex operator++(int)// to avoid this expression: a++++
{
Complex tmp(*this);
++*this;
return tmp;
} ostream& Print(ostream& os) const
{
return os << ....;
}
private:
double real_, imaginary_;
}; const Complex operator+(const Complex& a, const Complex& b)
{
Complex ret(a);
ret += b;
return ret;
} ostream& operator<<(ostream& os, const Complex& c)
{
return c.Print(os);
}
class Complex
- My simple implementation for class string:
https://github.com/yaoyansi/mymagicbox/blob/master/mystring/src/mystring.h
https://github.com/yaoyansi/mymagicbox/blob/master/mystring/src/mystring.cpp
- 避免使用公有 虚函数, 应该使用Template Method模式
- #include<iosfwd>
- operator new(), operator delete()都是static函数, 即使他们没有被声明为static
- 永远不要多态地使用数组. 使用vector<>/deque<>而不要使用数组
- 一般来说, 避免编写自动转换(隐式类型转换)的代码, 即转换操作符
- 不要编写非显示构造函数
- T t//调用默认构造函数
T t()//声明了一个函数
T t(u)//直接初始化, 用u初始化变量t
T t=u// 调用拷贝构造函数
尽可能使用T t(u), 而非T t=u
- 当非内置返回类型使用by value返回时, 最好返回一个 const 值
- 正确使用mutable, 是正确使用const的关键
-
class A { public: virtual ~A(); }
class B : private virtual A {};
class C : public A {}
class D : public B, public C {}
A a1; B b1; C c1; D d1;
const A a2;
const A& ra1 = a1;
const A& ra2 = a2;
char c;
A *pa; B *pb; C *pc;
pa = (A*)& ra1;// pa = const_cast<A*>(&ra1)
pa = (A*)&a2;//因为a2是一个const对象, 所以结果未定义
pb = (B*)&c1;//pb = reinterpret_cast<B*>(&c1)
pc = (C*)&d1;//C里是错误的, c++里不需要转换
- 不要转调const, 使用mutable代替.
- 不要使用inline, 除非性能分析显示它是必要的
- 不要使用全局或静态变量. 如果要用, 需要注意他们的初始化顺序.
- 在构造函数初始化列表中的基类, 应该按照其在类声明中出现的顺序列出.
- 在构造函数初始化列表中的成员变量, 应该按照其在类声明中出现的顺序列出.
<<Exceptional C++>> notes的更多相关文章
- ASP.NET Core 1.1.0 Release Notes
ASP.NET Core 1.1.0 Release Notes We are pleased to announce the release of ASP.NET Core 1.1.0! Antif ...
- Android Weekly Notes Issue #237
Android Weekly Issue #237 December 25th, 2016 Android Weekly Issue #237 这是本年的最后一篇issue, 感谢大家. 本期内容包括 ...
- Android Weekly Notes Issue #230
Android Weekly Notes Issue #230 November 6th, 2016 Android Weekly Issue #230. Android Weekly笔记, 本期内容 ...
- Android Weekly Notes Issue #229
Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...
- Android Weekly Notes Issue #227
Android Weekly Issue #227 October 16th, 2016 Android Weekly Issue #227. 本期内容包括: Google的Mobile Vision ...
- Android Weekly Notes Issue #221
Android Weekly Issue #221 September 4th, 2016 Android Weekly Issue #221 ARTICLES & TUTORIALS And ...
- Android Weekly Notes Issue #219
Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...
- 某墙尼妹,用个Response.Filter来解决StackExchange.Exceptional中google cdn的问题
某墙墙了古古路,一些开源的东东里用了古古路CDN,比如Exceptional,Opserver ,导致服务要么慢要么用不了 必须要替换之 Exceptional就只要用Response.Filter替 ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
随机推荐
- BZOJ 1468 树分治
求出子树的重心后求出它每个子节点的距离,排序后就可以统计距离小于等于K的点对的个数了,但是会在同一子树内重复,然后在每个子树里面减去小于等于K的点对个数就可以了. #include <iostr ...
- jython安装
下载了jython后:http://www.cr173.com/soft/9719.html 这是我当时下载的网站 官网很慢开始->运行->cmd->打开dos命令窗口,转到jyth ...
- Python 学习记录----利用Python绘制奥运五环
import turtle #导入turtle模块 turtle.color("blue") #定义颜色 turtle.penup() #penup和pendown()设置画笔抬起 ...
- 探索软件工程道路上的我III (Θ∀Θ#)
github地址:https://github.com/JUNYU217/2016-03-08 开发语言:Java 开发工具:UltraEdit || 为月末了,网费欠了...很抱歉的拖了那么久的作业 ...
- SpringMVC之入门
Spring MVC简介 Spring MVC:Spring MVC也叫Spring Web MVC,属于表现层框架,是Spring中的一份子. Spring MVC执行流程图 第一个SpringMV ...
- bootstrap 之 xs,sm,md,lg && 主要颜色
mobile – xs ( <768px ) tablet – sm ( 768~991px ) desktop – md ( 992~1170px ) large desktop – lg ( ...
- php策略模式
一.编写一个简单的网页计算器功能 代码片段: 视图页面(两个输入框,一个下拉列表选择操作符,一个计算按钮) 后台php程序处理(最原始的写法) 假如新加一个运算方式(取余),那么就得修改php后台程序 ...
- Ubuntu Sublime Text 设置等宽字体
{ "font_face": "DejaVu Sans Mono", "font_size": 10, "word_wrap&qu ...
- 从小工到专家 ——读《Java程序员职场全攻略》有感
从小工到专家 ——读<Java程序员职场全攻略>有感 <Java程序员职场全攻略>是以故事的形式,向读者介绍Java程序员的职场经验.作者牛开复在北京从事软件开发,已经是一 ...
- textarea关于空格和换行那点事
textarea中空格连续输入多个的情况下,数据回显的时候页面只是显示一个:换行同样有问题,在textarea中有换行,在页面上却没有,今天终于看到个写的比较具体的文章,拿过来收藏下. 地址链接: h ...