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:~$
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语