首页
学习
活动
专区
工具
TVP
发布

C++核心准则原文翻译

专栏作者
465
文章
265666
阅读量
44
订阅数
自学HarmonyOS应用开发(62)- 使用对象关系映射数据库保存设定信息
除了地图数据,秒表应用还有一些其他希望保存的数据,例如上次定位的位置,地图画面的缩放比例等。本文介绍通过对象关系映射数据库技术保存这些信息的方法。
面向对象思考
2021-08-06
5230
自学HarmonyOS应用开发(55)- 使用对象关系映射数据库保存地图数据
前一篇文章实现了地图数据的正确表示,但是由于每次执行都需要至少一次从网上获取地图数据,不可避免地产生显示延迟。本文介绍利用对象数据库储存已经获取的地图数据,从而避免重复下载相同数据并大幅度提高初次显示速度的方法。
面向对象思考
2021-08-06
6560
自学鸿蒙应用开发(22)- 定义和使用字符串资源
到到这篇文章之前,我们的所有字符串都是直接在代码中或者是嗯布局文件中直接使用的。这种方法虽然简单明快,但是如果我们需要修改这些字符串的时候,就需要在各处寻找定义的字符串并且修改它们。另外一个问题是,如果我们在不同的地方,希望使用同一个字符串,这种分别定义和使用的方式就无法满足需求。通过资源文件定义字符串可以解决这个问题。具体定义的方法参考下面string.json文件中的代码。:
面向对象思考
2021-02-25
1.1K0
C++核心准则​讨论:切勿让指针的生命周期超出其指向的对象
Discussion: Never let a pointer outlive the object it points to
面向对象思考
2020-12-31
6570
C++核心准则​讨论:将基类的析构函数设为公共和虚拟的,或受保护的和非虚拟的
Discussion: Make base class destructors public and virtual, or protected and non-virtual 讨论:将基类的析构函数
面向对象思考
2020-12-15
1.1K0
C++核心准则​讨论:如果在初始化期间需要“虚行为”,请使用工厂函数
If your design wants virtual dispatch into a derived class from a base class constructor or destructor for functions like f and g, you need other techniques, such as a post-constructor -- a separate member function the caller must invoke to complete initialization, which can safely call f and g because in member functions virtual calls behave normally. Some techniques for this are shown in the References. Here's a non-exhaustive list of options:
面向对象思考
2020-12-15
4410
C++核心准则​讨论:按照成员声明的顺序定义和初始化成员变量
Member variables are always initialized in the order they are declared in the class definition, so write them in that order in the constructor initialization list. Writing them in a different order just makes the code confusing because it won't run in the order you see, and that can make it hard to see order-dependent bugs.
面向对象思考
2020-12-15
8050
C++核心准则​附录B:代码现代化
Ideally, we follow all rules in all code. Realistically, we have to deal with a lot of old code:
面向对象思考
2020-12-15
3310
C++核心准则​:注释风格
Compilers do not read comments. Comments are less precise than code. Comments are not updated as consistently as code.
面向对象思考
2020-11-26
4480
C++核心准则​NL.5:避免在名称中包含类型信息
If names reflect types rather than functionality, it becomes hard to change the types used to provide that functionality. Also, if the type of a variable is changed, code using it will have to be modified. Minimize unintentional conversions.
面向对象思考
2020-11-25
7050
C++核心准则​GSL.view:视图
These types allow the user to distinguish between owning and non-owning pointers and between pointers to a single object and pointers to the first element of a sequence.
面向对象思考
2020-11-16
4740
C++核心准则​NR.1:不要坚持所有声明都应该放在函数顶部
The "all declarations on top" rule is a legacy of old programming languages that didn't allow initialization of variables and constants after a statement. This leads to longer programs and more errors caused by uninitialized and wrongly initialized variables.
面向对象思考
2020-11-10
3940
C++核心准则​Pro.bounds:边界安全群组
This profile makes it easier to construct code that operates within the bounds of allocated blocks of memory. It does so by focusing on removing the primary sources of bounds violations: pointer arithmetic and array indexing. One of the core features of this profile is to restrict pointers to only refer to single objects, not arrays.
面向对象思考
2020-11-10
5980
C++核心准则​NR.5:不要使用两阶段初始化
Splitting initialization into two leads to weaker invariants, more complicated code (having to deal with semi-constructed objects), and errors (when we didn't deal correctly with semi-constructed objects consistently).
面向对象思考
2020-11-10
4720
C++核心准则​A.1-A.4:架构理念
Isolating less stable code facilitates its unit testing, interface improvement, refactoring, and eventual deprecation.
面向对象思考
2020-11-03
2970
C++核心准则SL.str.4:使用char*参照单独字符
The variety of uses of char* in current code is a major source of errors.
面向对象思考
2020-10-30
4060
C++核心准则​SL.str.3:使用zstring或czstring引用C风格0结尾的字符串序列
Readability. Statement of intent. A plain char* can be a pointer to a single character, a pointer to an array of characters, a pointer to a C-style (zero-terminated) string, or even to a small integer. Distinguishing these alternatives prevents misunderstandings and bugs.
面向对象思考
2020-10-30
6860
C++核心准则​​SL.str.2:使用std::string_view或者gsl::span<char>参照字符序列
SL.str.2:使用std::string_view或gsl::span<char>参照字符序列
面向对象思考
2020-10-30
8310
C++核心准则​​SL.str.1:使用std::string管理字符序列
string correctly handles allocation, ownership, copying, gradual expansion, and offers a variety of useful operations.
面向对象思考
2020-10-30
4570
C++核心准则SL.con.4:不要对不能直接拷贝的参数使用memset或memcpy
Doing so messes the semantics of the objects (e.g., by overwriting a vptr).
面向对象思考
2020-10-30
6020
点击加载更多
社区活动
RAG七天入门训练营
鹅厂大牛手把手带你上手实战
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档