<<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 ...
随机推荐
- oracle xmltype导入并解析Excel数据 (三)解析Excel数据
包声明 create or replace package PKG_EXCEL_UTILS is -- Author: zkongbai-- Create at: 2016-07-06-- Actio ...
- How can i use iptables save on centos 7?
I installed CentOS 7 with minimal configuration (os + dev tools). I am trying to open 80 port for ht ...
- 汇编中bss,data,text,rodata,heap,stack,意义
bss段: BSS段(bsssegment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文BlockStarted by Symbol的简称.BSS段属于静态内存分配. data ...
- 解决Android应用安装快完毕时提示签名冲突
最近开发了一个Android手机应用,自己用Eclipse调试安装没问题,使用其他人调试生成的bin下的apk就会出现问题,安装到最后提示"安装签名冲突"错误,想了一下估计是没有给 ...
- android studio fetching android sdk component information
解决办法: 1.找到Android Studio安装目录下的idea.properties文件 2.增加disable.android.first.run=true
- js中的break ,continue, return (转)
面向对象编程语法中我们会碰到break ,continue, return这三个常用的关键字,那么关于这三个关键字的使用具体的操作是什么呢?我们在使用这三关键字的时候需要注意和需要理解的规则是什么呢? ...
- storyboard tabbarcontroller设置tab的图片
在storyboard里逐项设置了图片,咦,怎么是颜色?别急,慢慢来 找到你的tabbarcontroller指向的viewcontroller,在viewdidload里做如下事,搞定 - (voi ...
- GitHub的用法:到GitHub上部署项目
先提供两个较好的Git教程: 1. 如何在github部署项目: lhttp://jingyan.baidu.com/article/656db918fbf70ce381249c15.html 2. ...
- Android驱动开发前的准备(四)
源代码的下载和编译 4.1 下载.编译和测试Android源代码 4.2下载和编译linux内核源代码 4.1.1 配置Android源代码下载环境 (1) 创建一个用于存放下载脚本文件的目录 # m ...
- 【转载】让你的MATLAB代码飞起来
原文地址:http://developer.51cto.com/art/201104/255128_all.htm MATLAB语言是一种被称为是"演算纸"式的语言,因此追求的是方 ...