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++(中文版)
184
5
C++14
,上述代码仍然成立,不过我们可以利用别名模板来去掉
std::enable_if
std::decay
累赘的“
typename
”和“
::type
”部分,从而产生下面这段更加养眼的代码:
class Person {
// C++14
public:
template<
typename T,
typename = std::enable_if_t<
//
这里代码量更少
!std::is_base_of<Person,
std::decay_t<T>
//
还有这里
>::value
>
//
还有这里
>
explicit Person(T&& n);
};
好吧,我承认我在说谎。我们仍然不能说已经完工,但我们业已接近,接近得不能再
接近了。我诚实着呢。
我们已经看到如何运用
std::enable_if
来为那些本来就想使用
Person
类的复制和移
动构造函数的型别选择性地禁用
Person
类中接受万能引用的构造函数,但我们还没有
看到如何运用这一技术来区分实参是整型还是非整型。而后者,毕竟才是我们最原始
的目标。构造函数的多义词问题,一路上都在牵扯着我们注意力。
我们需要做的一切(这一回真的是所有工作了)就是:①为
Person
类添加一个处理
整型实参的构造函数重载版本;②进一步限制模板构造函数,在接受整型实参时禁用 ...
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