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++(中文版)
46
2
不是什么新鲜事,而只是采纳了在其他编程语言中称为型别推导的东西而已。其他的
静态型别过程式语言(如
C#
D
Scala
Visual Basic
)中或多或少都有这么一个等
价的特性,更不用说一系列静态型别函数式语言(如
ML
Haskell
OCaml
F#
等)。
这些语言之所以要引入如此特性,部分原因在于动态型别语言的成功,而在后者中变
量很少有显式型别。软件开发社区已经积累了丰富的型别推导方面的经验,而这也说
明此类技术并不会与撰写和维护大型的、工业强度的基础代码这样的工作产生冲突。
有些程序员会觉得使用了
auto
以后,就不能一眼从源代码中看出对象的型别,因而
感觉烦恼。但是,
IDE
的对象型别显示能力往往会缓和这个问题(即使考虑到条款
4
中提及的
IDE
的型别显示缺陷),并且,在很多情况下,对于对象型别的抽象理解可
能和了解它的精确型别同等有用。比如说,知道某个对象是个容器、是个计数器,还
是个智能指针就已经够用了,没有必要了解它具体是哪种型别的容器、计数器或智能
指针。如果再取个好一点的变量名字,那么一些抽象型别信息就近乎总是唾手可得了。
事实上,显式地写出型别经常是画蛇添足,带来各种微妙的偏差,有些关乎正确性,
有些关乎效率,或是两者都受影响。还有,
auto
型别可以随着其初始化表达式的型别
变化而自动随之改变,这就意味着通过使用
auto
,有一些重构动作就被顺手做掉了。
例如,假设有一个函数本来声明的返回型别是
int
,但后来又觉得
long
更合适一些,
那么如果函数调用的结果是存储在
auto ...
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