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++(中文版)
auto
51
后,下标
5
被应用到了该指针指涉到的比特,如此浮现出来的
bool
值就被用来初始
highPriority
Matrix
这个例子中,使用带显式型别的初始化物习惯用法以后,代码就会写成这样:
auto
sum =
static_cast<Matrix>(
m1 + m2 + m3 + m4
)
;
这种习惯用法的应用并不限于会产生代理型别别的初始化物。它同样可以应用于你想
要强调你意在创建一个型别有异于初始化表达式型别的变量的场合,例如,假设你有
一个计算某容差值的函数。
double calcEpsilon();
//
返回容量差
calcEpsilon
显然返回一个
double
,但是假如你了解对于你的应用程序来说,
float
精度已经够用,另外你也在乎
float
double
之间的尺寸差异。你可以声明一个
float
变量来存储
calcEpsilon
的结果。
float ep = calcEpsilon();
//
进行从
double
float
的隐式型别转换
但这样的写法难以表明“我故意降低了函数的返回值精度”,而一个采用了带显式型
别的初始化物习惯用法的声明却可以做到:
auto
ep =
static_cast<float>(
calcEpsilon()
)
;
如果你需要故意把浮点表达式存储为整型,也可以采用相似的理念。假定你需要某个
计算带有随机访问迭代器的容器(例如一个
std::vector
std::deque
std::array
中的某个元素的下标,而给到你的是一个
double
型别的、在 ...
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