C++核心准则原文翻译

303 篇文章
31 人订阅

全部文章

面向对象思考

C++核心准则C.183: 不要使用联合体实现双关类型

It is undefined behavior to read a union member with a different type from the o...

7010
面向对象思考

C++核心准则C.182:使用匿名联合体实现附带标签的联合体

A well-designed tagged union is type safe. An anonymous union simplifies the def...

10510
面向对象思考

C++核心准则C.181:避免使用"暴露的"联合体

A naked union is a union without an associated indicator which member (if any) i...

6210
面向对象思考

C++核心准则C.180:使用联合体节约内存

A union allows a single piece of memory to be used for different types of object...

8220
面向对象思考

C++核心准则C.170: 如果感觉需要重载lambda表达式,使用泛型lambda表达式​

You cannot overload by defining two different lambdas with the same name.

9310
面向对象思考

C++核心准则C.168: 将重载的运算符定义在操作对象的命名空间内

C.168: Define overloaded operators in the namespace of their operands

7110
面向对象思考

C++核心准则C.167:为具有约定俗成​语义的操作使用运算符

Readability. Convention. Reusability. Support for generic code。

5910
面向对象思考

C++核心准则C.166:​ 重载的单目运算符&只能用于智能指针和引用

The & operator is fundamental in C++. Many parts of the C++ semantics assumes it...

5830
面向对象思考

C++核心准则C.165: 为定制点使用using关键字​

To find function objects and functions defined in a separate namespace to "custo...

6310
面向对象思考

C++核心准则:C.164:避免隐式转换运算符

Implicit conversions can be essential (e.g., double to int) but often cause surp...

6210
面向对象思考

C.163: 重载只用于基本等价的操作

Having the same name for logically different functions is confusing and leads to...

6120
面向对象思考

C++核心准则C.162:将大致相同的操作设计为重载函数​

Having different names for logically equivalent operations on different argument...

5410
面向对象思考

C++核心准则C.161:对称运算使用非成员函数​运算符

If you use member functions, you need two. Unless you use a nonmember function f...

4920
面向对象思考

C++核心准则C.160:定义运算符主要是为了模仿习惯用法

Here, the conventional semantics is maintained: Copies compare equal.

4310
面向对象思考

C++核心准则C.152:永远不要将派生类数组的指针赋值给基类指针

Subscripting the resulting base pointer will lead to invalid object access and p...

5310
面向对象思考

C++核心准则C.151:使用make_shared构建shared_ptr管理的对象

make_shared gives a more concise statement of the construction. It also gives an...

7910
面向对象思考

C++核心准则C.150:unique_ptr管理的对象要用make_unique()​构建

make_unique gives a more concise statement of the construction. It also ensures ...

7920
面向对象思考

C++核心准则C.149:使用unique_ptr或者shared_ptr避免忘记销毁使用new创建的对象

C.149:使用unique_ptr或者shared_ptr避免忘记销毁使用new创建的对象

8920
面向对象思考

C++核心准则C.148:使用dynamic_cast进行指针类型转换时,将不能发现目标类看作是有效的选项

C.148:使用dynamic_cast进行指针类型转换时,将不能发现目标类看作是有效的选项

6510
面向对象思考

C++核心准则C.146:如果无法避免在继承层次中移动,使用dynamic_cast

Use of the other casts can violate type safety and cause the program to access a...

6510

扫码关注云+社区

领取腾讯云代金券