Skip to Content
Effective Modern C++(中文版)
book

Effective Modern C++(中文版)

by Scott Meyers
April 2018
Intermediate to advanced
303 pages
4h 54m
Chinese
China Electric Power Press Ltd.
Content preview from Effective Modern C++(中文版)
转向现代
C++
95
void doWork()
noexcept
{
setup();
//
建立要做的工作
//
完成要做的工作
cleanup();
//
执行清理动作
}
这里
doWork
带有
noexcept
声明,尽管它调用了不带
noexcept
声明的函数
setup
cleanup
。这看起来自相矛盾,但也有可能是
setup
clean
经在文档中写明它们
不会发射异常,尽管它们并没有加上这么一个声明。而不加这么一个声明,也可能有
充分的理由。例如,它们可能来自于使用
C
语言撰写的库(即使是那些来自
C
标准
库中被移入
std
名字空间的函数也都没有加上异常规格,例如,
std::strlen
就不带
noexcept
声明)。又或者它们可能来自一个
C++98
库,当时决定不采用
C++98
异常
规格,又还没来得及根据
C++11
标准做修订。
由于有着确实的理由使得带有
noexcept
声明的函数依赖于缺乏
noexcept
保证的代码,
C++
允许此类代码通过编译,并且编译器通常不会就此生成警告。
要点速记
noexcept
声明是函数接口的组成部分,这意味着调用方可能会对它有依赖。
相对于不带
noexcept
声明的函数,带有
noexcept
声明的函数有更多机会
得到优化。
noexcept
性质对于移动操作、
swap
、函数释放函数和析构函数最有价值。
大多数函数都是异常中立的,不具备
noexcept
性质。
条款
15
:只要有可能使用
constexpr
,就使用它
如果
C++ ...
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

流畅的Python(第2版)

流畅的Python(第2版)

Luciano Ramalho
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787519817749