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版)

3.7 建议

[1] 区分声明(用作接口)和定义(用作实现);3.1节。

[2] 使用头文件描述接口、强调逻辑结构;3.2节;[CG:SF.3]。

[3] 使用#include将头文件包含到实现其函数的源文件中;3.2节;[CG:SF.5]。

[4] 在头文件中应避免定义非内联函数;3.2节;[CG:SF.2]。

[5] 优先选择module而非头文件(在支持module的地方);3.3节。

[6] 用名字空间表达逻辑结构;3.4节;[CG:SF.20]。

[7] 将using指示用于程序转换、基础库(如std)或局部作用域中;3.4节;[CG:SF.6][CG:SF.7]。

[8] 不要在头文件中使用using指示;3.4节;[CG:SF.7]。

[9] 抛出一个异常来指出你无法完成分配的任务;3.5节;[CG:E.2]。

[10] 异常只用于错误处理;3.5.3节;[CG:E.3]。

[11] 预计直接调用者会处理错误时就使用错误码;3.5.3节。

[12] 如果通过很多函数调用预计错误会向上传递,则抛出异常;3.5.3节。

[13] 如果对使用异常还是错误码存疑,优先选择异常;3.5.3节。

[14] 在设计早期就规划好错误处理策略;3.5节;[CG:E.12]。

[15] 用专门设计的用户自定义类型(而非内置类型)作为异常;3.5.1节。

[16] 不要试图在每个函数中捕获所有异常;3.5节;[CG:E.7]。

[17] 优先选择RAII而非显式的try块;3.5.1节、3.5.2节;[CG:E.6]。

[18] 如果你的函数不抛出异常,那么将其声明成noexcept;3.5节;[CG:E.12]。

[19] 令构造函数建立不变式,如果不成功,就抛出异常;3.5.2节;[CG:E.5]。 ...

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