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++
101
需要重点提请注意的是,
constexpr
是对象和函数接口的组成部分。
constexpr
际上
宣告的是:“但凡任何
C++
要求在此使用一个常量表达式的语境,皆可以用我。”一
旦你把一个对象或函数声明成了
constexpr
,客户就可以将其用于这种语境。而万一
你后来又感觉你对
constexpr
的运用不当,然后移除了它,这个动作就可以导致无穷
无尽的客户代码被拒绝编译(仅仅是向函数体里出于调试或性能调优的目的而增添一
I/O
语句就可能导致这么个局面,因为通常来说,
constexpr
函数里是不允许有
I/O
语句的)。“只要有可能使用
constexpr
,就使用它”这句话中的“只要有可能”的
含义就是你是否有一个长期的承诺,将由
constexpr
带来的种种限制施加于相关的函
数和对象之上。
要点速记
constexpr
对象都具备
const
属性,并由编译期已知的值完成初始化。
constexpr
函数在调用时若传入的实参值是编译期已知的,则会产出编译期
结果。
比起非
constexpr
对象或
constexpr
函数而言,
constexpr
对象或是
constexpr
函数可以用在一个作用域更广的语境中。
条款
16
:保证
const
成员函数的线程安全性
在数学领域中,使用一个类来表示多项式会非常方便。而在这个类中,若有一个函数
能够计算多项式的根,即那些使得多项式求值结果为零的值,将会很有用。这样一个
函数并不会造成多项式的值的改动,因此将它声明为
const
成员函数也很自然。
class Polynomial ...
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

C++程序设计:原理与实践(基础篇)(原书第2版)

C++程序设计:原理与实践(基础篇)(原书第2版)

本贾尼 斯特劳斯特鲁普
C++语言导学(原书第2版)

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

本贾尼 斯特劳斯特鲁普
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787519817749