《Exceptional C++中文版》章节试读

出版社:中国电力出版社
出版日期:2003-3
ISBN:9787508314853
作者:萨特 (Sutter Herb)
页数:220页

《Exceptional C++中文版》的笔记-第105页

将编译期依存性减至最小。
#include <iosfwd>
前置声明
Page109
Pimpl
句柄/实体的一种特殊形式
Pimpl 习惯用法
编译器防火墙
Pimpl 只是一种用来隐藏类的私有成员的非透明指针。
Page119
Fast Pimpl
static const size_t sizeofx;
char x_[sizeofx];
assert
new (&x_[0]) X
reinterpret_cast<X*>(&x[0])->~X();
::operator new()
malloc()
static void* operator new (size_t);
static void operator delete (void*);
Page127
名字查找和接口规则
Koenig 查找规则
接口规则
namespace
{
}
class
{
};
Page143
名字隐藏
d.Base::g(i);
using B::g;

《Exceptional C++中文版》的笔记-第171页

对象标识
自动转换
转换操作符
非显式的构造函数
对象生成期
Page189
const
不要声明 const 的按值传递的函数参数
const
mutable
Page196
类型转换
`const_cast
`dynamic_cast
`reinterpret_cast
`static_cast
bool
`typedef ... bool
`#define bool ...
`enum bool ...
`class bool ...
传递调用函数
Page206
控制流

《Exceptional C++中文版》的笔记-第168页

封装指针成员
class
{
public: // ...
protected: // ...
private:
auto_ptr<T> pimpl_;
};
*资源管理类
const auto_ptr<T>
`operator *()
`operator ->()
`get()
不能做 =、release、reset 等操作

《Exceptional C++中文版》的笔记-第80页

重载虚函数
using Base::f;
Page85
类的关系
Page94
继承的使用和滥用
Liskov 替换规则
不要求更多,也不承诺更少。
Page103
面向对象程序设计

《Exceptional C++中文版》的笔记-第27页

编写异常安全的代码
代码的复杂性

《Exceptional C++中文版》的笔记-第73页

类的设计与继承
T& T::operator +=(const T& other)
{
// ...
return *this;
}
const T operator +(const T& a, const T& b)
{
T temp(a);
temp += b;
return temp;
}
一个设计和风格良好的类
class Complex
{
public:
explicit Complex(double real, double imaginary = 0) : real_(real), imaginary_(imaginary)
{
}

Complex& operator +=(const Complex& other)
{
real_ += other.real_;
imaginary_ += other.imagniary_;
return *this;
}

Complex& operator ++()
{
++real_;
return *this;
}
const Complex operator ++(int)
{
Complex temp(*this);
++*this;
return temp;
}

ostream& print(ostream& os) const
{
return os << "(" << real_ << ", " << imaginary_ << ")";
}

private:
double real_, imaginary_;
};
const Complex operator +(const Complex& lhs, const Complex& rhs)
{
Complex ret(lhs);
ret += rhs;
return ret;
}
ostream& operator <<(ostream& os, const Complex& c)
{
return c.print(os);
}

《Exceptional C++中文版》的笔记-第1页

第一章 泛型程序设计与 C++ 标准库
Page1
异常安全性
迭代器
临时对象
迭代器:
·有效值
·有效生存期
·有效范围
·非法的内置类型操作
Page4
不区分大小的字符串
stricmp()
typedef basic_string<char> string;
struct ci_char_traits : public char_traits<char>
{
static bool eq(char c1, char c2)
{
return toupper(c1) == toupper(c2);
}
static bool lt(char c1, char c2)
{
return toupper(c1) < toupper(c2);
}
static int compare(const char* s1, const char* s2, size_t n)
{
return memicmp(s1, s2, n);
}
static const char* find(const char* s, int n, char a)
{
while (n-- > 0 && toupper(*s) != toupper(a))
{
++s;
}
return n > 0 ? s : 0;
}
};
typedef base_string<char, ci_char_traits> ci_string;
Page8
不区分大小写的字符串
LSP Liskov 替换规则
Page11
最大可重用的泛型容器
template <typename T, size_t size>
class fixed_vector
{
};
Page12
最大可重用的泛型容器
operator=
强类型安全性
Page19
临时对象
const& 常量引用
Page24
使用标准库(或称再谈临时对象)
find
sort

《Exceptional C++中文版》的笔记-第151页

内存管理
C++ 的内存区域:
·常量数据(字符串字面值)
·栈(自动变量)
·自由存储(new/delete)
·堆(malloc/free)
·全局或静态(静态成员,全局变量,文件范围变量)


 Exceptional C++中文版下载


 

外国儿童文学,篆刻,百科,生物科学,科普,初中通用,育儿亲子,美容护肤PDF图书下载,。 零度图书网 

零度图书网 @ 2024