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 红包祝福语简短10字
18 周六早晨祝福语简短