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++(中文版)
右值引用
移动语义和完美转发
199
论就是:
0
NULL
都不能用作空指针以进行完美转发。不过,修正方案也颇简单:传
nullptr
,而非
0
NULL
欲知详情,请参阅条款
8
仅有声明的整型
static const
成员变量
有这么个普适的规定:不需要给出类中的整型
static const
成员变量的定义,仅需
声明之。因为编译器会根据这些成员的值实施常数传播,从而就不必再为它们保留内
存。举个例子,考虑下面这段代码:
class Widget {
public:
static const std::size_t MinVals = 28;
//
给出了
MinVals
的声明
};
//
未给出
MinVals
的声明
std::vector<int> widgetData;
widgetData.reserve(
Widget::MinVals
);
//
此处用到了
MinVals
在这里,尽管
Widget::MinVals
(以下简称
Minvals
)并无定义,我们还是利用了
MinVals
来指定
widgetData
的初始容量。编译器绕过了
MinVals
少定义的事实
(编译器的行为是这样规定的),手法是把值
28
塞到所有提及
MinVals
之处。未为
MinVals
的值保留存储这一事实并不会带来问题。如果产生了对
MinVals
实施取址的
需求(例如,有人创建了一个指涉到
MinVals
的指针),
MinVals
就得要求存储方可
(因此指针才能够指涉到它),然后上面这段代码虽然仍能够通过编译 ...
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