<<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 ...
随机推荐
- linux编译c文件
1.创建.c文件,比如在firstmake文件夹创建了一个a.c文件,那么编译语句为: gcc -o firstmake a.c //格式为文件夹名 文件名 2.然后就会生成一个firstmake.o ...
- strip_tags() 函数
定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...
- [GodLove]Wine93 Tarining Round #6
比赛链接: http://vjudge.net/contest/view.action?cid=47642#overview 题目来源: 2012 ACM/ICPC Asia Regional Jin ...
- 收拾那掉了一地的session
多个页面有如下多个session,本来可能是如下面这样的 Session["UId"] = 10; Session["UName"] = "test& ...
- 解析C#开发过程常见的编程模式
单例模式: 在多线程的程序开发过程中经常会遇到单例模式[单件模式],它的特点是不是根据客户程序的调用而生成新的实例,而是控制某个类型的实例数量只有一个.也就是说,单例模式就是保证在整个应用程序的生命周 ...
- 论文ei,sci检索,JCR-SCI分区,中科院分区连接
https://jcr.incites.thomsonreuters.com/JCRJournalHomeAction.action?SID=B1-bQgax2FJ7EsyZ9muP6O5loc77S ...
- 折腾域名的dns
最近,购买域名的时候遇到了几个概念,刚开始不是很懂,最后都是直接找客服给我改好的,现在小结一下帮助理解. DNS域名管理是按后缀进行分组的,比如.com域名,作为最早的商用域名,有很高的推广价值.再比 ...
- Egit Patch
Git为我们提供了Patch功能,Patch中包含了源码更改的描述,能够应用于其他Eclipse工作空间或者Git仓库.也就是说,可以将当前提交导出至其他分支或者项目中. 举个例子,项目A.B中使 ...
- Autofac 同时支持MVC 与Webapi
1.引用 using Autofac; using Autofac.Integration.Mvc; using Autofac.Integration.WebApi; 2.在Global中的Appl ...
- h5移动端-1
iphone3 : 设备分辨率 : 320*480 屏幕分辨率 : 320*480 iphone4 : 设备分辨率 : 320*480 屏幕分辨率 : 640*960 iphone5 : 设备分辨率 ...