Skip to Content
C++语言导学(原书第2版)
book

C++语言导学(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
5h 35m
Chinese
Pearson
Content preview from C++语言导学(原书第2版)

5.5 建议

[1] 要控制对象的构造、拷贝、移动和析构;5.1.1节;[CG:R.1]。

[2] 构造函数、赋值操作和析构函数要设计为一组匹配的操作;5.1.1节;[CG:C.22]。

[3] 要么定义所有的基本操作,要么什么也不定义;5.1.1节;[CG:C.21]。

[4] 如果默认构造函数、赋值操作或析构函数是适合的,就让编译器去生成它们(不要自己重写);5.1.1节;[CG:C.20]。

[5] 如果类有一个指针成员,它就可能需要用户自定义的析构函数、拷贝操作和移动操作,或者禁止它们;5.1.1节;[CG:C.32][CG:C.33]。

[6] 如果类具有一个析构函数,它就可能需要用户自定义的拷贝和移动操作,或者禁止它们;5.2.1节。

[7] 默认将单参数构造函数声明为explicit的;5.1.1节;[CG:C.46]。

[8] 如果类成员有合理的默认值,以数据成员初始值的方式为其提供此默认值;5.1.3节;[CG:C.48]。

[9] 对于一个类型,如果默认拷贝语义不适合,重定义或禁止拷贝操作;5.2.1节、4.6.5节;[CG:C.61]。

[10] 通过传值方式返回容器(依赖移动操作提高性能);5.2.2节;[CG:F.20]。

[11] 对大的运算对象,采用const引用参数类型;5.2.2节;[CG:F.16]。

[12] 提供强资源安全。即,永远不泄漏任何可视为资源的东西;5.3节;[CG:R.1]。

[13] 如果某个类是一个资源句柄,则它需要一个用户自定义的构造函数、一个析构函数以及非默认的拷贝操作;5.3节;[CG:R.1]。

[14] 重载运算符应模仿常规用法;5.4节;[CG:C.160]。

[15] 遵循标准库容器设计;5.4.2节;[CG:C.100]。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787111633280