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++(中文版)
52
3
转向现代
C++
C++11
C++14
中“知名特性”可谓琳琅满目:
auto
、智能指针、移动语义、
lambda
式、
并发,不一而足。这些特性都很重要,我为它们中的每一个都分配了整整一章来讲述。
掌握这些特性固然重要,但是要成为一名高效的现代
C++
程序员还需要一系列的小
步快跑。这每一小步都在回答从
C++98
转向现代
C++
之旅中浮现的一些特定问题。
在创建对象时,什么时候应该使用大括号而非小括号?为何别名声明优于
typedef
constexpr
const
有何不同?
const
员函数和线程安全有何关系?这个问题列表
会越来越长。而我们在本章内会把这些问题各个击破。
条款
7
:在创建对象时注意区分
()
{}
取决于你怎么看了,
C++11
中进行对象初始化的语法选择带来的或是选择太多的无所
适从,或是眼花缭乱的左右为难。总而言之,指定初始化值的方式包括使用小括号、
使用等号,或是使用大括号:
int x
(
0
)
;
//
初始化物在小括号内
int y
=
0;
//
初始化物在等号之后
int z
{
0
}
;
//
初始化物在大括号内
在很多情况下,使用一个等号和一对大括号也是可以的:
int z
= {
0
}
;
//
使用等号和大括号来指定初始化物
在本条款其余部分,一般我将忽略这种“等号加大括号”语法,因为
C++
通常会把它
和只有大括号的语法同样处理。
转向现代
C++
53
“眼花缭乱”派会指出,使用一个等号来书写初始化语句往往会让
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