<<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 ...
随机推荐
- 【LeetCode】Product of Array Except Self
Product of Array Except Self Given an array of n integers where n > 1, nums, return an array outp ...
- c#中方法的重载
转自:http://www.cnblogs.com/lovesong_blog/articles/1416617.html string和program都是Object的派生类,string类型是se ...
- ionic 打包签名
IONIC用一下命令打包会自动签名并且打包 ionic build android 自己签名并且打包方法: 1>在你项目app\platforms\android目录下新建文件:debug-si ...
- 解析C语言结构体对齐(内存对齐问题)
C语言结构体对齐也是老生常谈的话题了.基本上是面试题的必考题.内容虽然很基础,但一不小心就会弄错.写出一个struct,然后sizeof,你会不会经常对结果感到奇怪?sizeof的结果往往都比你声明的 ...
- ios系统(苹果手机)按钮显示为圆角和渐变的问题
按钮在安卓手机上显示正常,但在苹果手机上会显示如下: 解决办法:给该按钮的样式加上:-webkit-appearance:none;这样按钮就会显示正常
- python3 如何使用ip、爬虫
使用urllib.request.random模块,不说了贴代码 url="*"; iplist=['70.254.226.206:8080'];proxy_support=url ...
- fine-grained
鸟类图像分类,CUB-200-2011,可以适用于图片左右的调整.
- GithubPage 的简单使用
这是我第一次写博客,主要是记录自己前端学习的经历.这次写一下GitHubpage 的简单使用.我用这里并没有想挂博客,主要是挂自己的一些小作品应用到简历中. 第一步: 首先先注册Github账号,创建 ...
- Bootstrap模态框(MVC)
BZ这篇博客主要是为大家介绍一下MVC如何弹出模态框.本文如果有什么不对的地方,希望大神们多多指教,也希望和我一样的小菜多多学习.BZ在这里谢过各位. 首先要在页面加上一个点击事件: @Html.Ac ...
- HDU 1010 Tempter of the Bone(深度+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...