编程语言
首页 > 编程语言> > 《Effective Modern C++》第1章学习记录

《Effective Modern C++》第1章学习记录

作者:互联网

Deducing Types

C++98只支持函数模板(function template)的类型推导
C++11增加了auto 和decltypes
C++14在C++11的基础上扩展了auto和decltype的适用范围

在一处改变原类型,可自动推导出其它地方的类型

大部分类型自动推导发生在函数模板调用上

Item1: Understand template type deduction

When the template type deduction rules are applied in the context of auto, they sometimes seem less intuitive than when they’re applied to templates.

 void myFunc(int param[])
 void myFunc(int* param) // the same as above
 f(name);

Item2: Understand auto type deduction

auto x1 = 27;
auto x2(27);
auto x3 = {27};
auto x4{ 27 4};

Item3: Understand decltype4

Item4:Know how to view deduced types

Things to remember:

标签:27,Effective,auto,Modern,C++,deduction,template,type
来源: https://blog.csdn.net/tanshiqian/article/details/112915461