C++ 学习

显示声明析构函数

A move operation is not implicitly generated for a class where the user has explicitly declared a destructor. Furthermore, the generation of copy operations is deprecated in this case (§44.2.3). This can be a good reason to explicitly define a destructor even where the compiler would have implicitly provided one (§17.2.3).

显示声明析构函数,就不会隐式生成默认拷贝/移动构造函数,即使编译器能隐式生成析构函数,我们也是最好显示声明析构函数。

lambda表达式 (隐式函数对象)

[&](int a){ return a<x; } 类似于 func_object_name fon{x}

[]:不捕获任何变量
[&]:以引用的方式捕获
[=]:以拷贝值的方式捕获
[&x]:以引用的方式只捕获x变量

  1. 隐式生成函数对象
void f(const Vector<int>& vec, const list<string>& lst, int x, const string& s)
{
	cout << "number of values less than " << x
	<< ": " << count(vec,[&](int a){ return a<x; }) << '\n';
	cout << "number of values less than " << s
	<< ": " << count(lst,[&](const string& a){ return a<s; }) << '\n';
}
可变参数模板

谨记:把第一个参数和其他参数区分对待

template<typename T, typename... Tail>
void f(T head, Tail... tail)
{
	g(head); // do something to head
	f(tail...); // try again with tail
}
void f() { } // do nothing
语句作用域

for while if switch的 ()中声明的变量

auto的时候不能使用列表初始化

auto z1 {99}; // z1 is an initializer_list
auto z2 = 99; // z2 is an int

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值