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++(中文版)
36
1
这里我把变量的名字取为“变量名字
+Type
”的形式,因为这么一来错误消息就更有
可能产生有助于我找到所追寻的信息。对于上述代码,我使用的编译器之一给出的诊
断信息包含以下部分:
error: aggregate 'TD<
int
> xType' has incomplete type and
cannot be defined
error: aggregate 'TD<
const int
*> yType' has incomplete type
and cannot be defined
另一个编译器给出了同样的信息,只是形式不同:
error: 'xType' uses undefined class 'TD<
int
>'
error: 'yType' uses undefined class 'TD<
const int
*>'
除了格式各异以外,只要采用了这种手段,所有我测试过的编译器都产生出了包含有
用型别信息的错误消息。
运行时输出
使用
printf
来显示型别信息(我可没有教你用
printf
),这种方法只有到了运行
期才能使用,却可以对于型别输出的格式提供完全的控制。困难之处在于为你关心的
型别创立一种适于显示的字符表示。你可能会想,“这有什么难的,不就是
typeid
std::type_info::name
吗?”沿着这个思路下去,查看
x
y
的推导型别的任务
就落实成了以下代码:
std::cout <<
typeid(x).name()
<< '\n';
// display types ...
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
Effective STL

Effective STL

Scott Meyers

Publisher Resources

ISBN: 9787519817749