C++核心准则原文翻译

303 篇文章
31 人订阅

C++

面向对象思考

C++核心准则R.23: 使用make_unique构建unique_ptr

For convenience and consistency with shared_ptr.

6720
面向对象思考

C++核心准则R.20: 使用unique_ptr或者shared_ptr表示所有权

This will leak the object used to initialize p1 (only).

7010
面向对象思考

C++核心准则R.15: 应该成对重载分配和释放函数

Otherwise you get mismatched operations and chaos.

8110
面向对象思考

C++核心准则:R.13: 在一个表达式中最多只执行一次显式资源分配

If you perform two explicit resource allocations in one statement, you could lea...

8020
面向对象思考

C++核心准则R.3: 原始指针(T*)不应拥有所有权

There is nothing (in the C++ standard or in most code) to say otherwise and most...

10210
面向对象思考

C++核心准则R.2: 只在接口中表示单独对象使用原始指针​

R.2: In interfaces, use raw pointers to denote individual objects (only)

9410
面向对象思考

C++核心准则R.1: 使用资源句柄自动管理资源并RAII(资源获取即初始化)

To avoid leaks and the complexity of manual resource management. C++'s language-...

9820
面向对象思考

C++核心准则Enum.8:只在必要时指定枚举值

Enum.8: Specify enumerator values only when necessary

7310
面向对象思考

C++核心准则Enum.7: 只在必要时定义枚举的底层类型

The default is the easiest to read and write. int is the default integer type. i...

6210
面向对象思考

C++核心准则Enum.6:避免无名枚举

If you can't name an enumeration, the values are not related

6410
面向对象思考

C++核心准则Enum.5: 不要使用全部大写的枚举值

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#enu...

6720
面向对象思考

C++核心准则Enum.4:为枚举类型定义运算符以便安全又简单地使用

Convenience of use and avoidance of errors.

9510
面向对象思考

C++核心准则Enum.3:枚举类​要比普通的枚举类型好

To minimize surprises: traditional enums convert to int too readily.

8220
面向对象思考

C++核心准则Enum.2: 使用枚举表现一组相关的命名常量

An enumeration shows the enumerators to be related and can be a named type.

8320
面向对象思考

C++核心准则Enum.1: 枚举类型比宏定义好

Macros do not obey scope and type rules. Also, macro names are removed during pr...

8310
面向对象思考

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

扫码关注云+社区

领取腾讯云代金券