C ++中的reference_wrapper
在C++中,reference_wrapper是一个类模板,可通过将引用包装在类型为T的可复制构造和可复制分配对象中来提供帮助。std::reference_wrapper的实例基本上是对象,但可以将它们转换为T&。因此,我们可以将通过引用使用基础类型的函数用作参数。
范例程式码
#include <iostream>
#include <functional>
using namespace std;
int main () {
char a = 'h', b = 'e', c = 'l', d = 'l', e = 'o' , f = 'W', g = 'o', h = 'r', i = 'l', j = 'd';
reference_wrapper<char> ref[] = {a, b, c, d, e, f, g, h, i, j}; //creating reference array
for (char& s : ref)
cout << s;
cout <<endl;
return 0;
}输出结果
soumyadeep@soumyadeep-VirtualBox:~$ ./a.out helloWorld soumyadeep@soumyadeep-VirtualBox:~$
热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短