c++引用包装器
#include<iostream>
template<class T>
void com(T arg)//模板函数,引用无效,引用包装器
{
std::cout <<"com ="<< &arg << "\n";
arg++;
}
int main()
{
int count = 10;
int & rcount = count;
com(count);
std::cout << count << std::endl;
//std::ref(变量) ,函数模板,引用包装器
//com(std::ref(count));
com(rcount);
std::cout << "main=" << &rcount << "\n";
std::cout << count << std::endl;
//std::cin.get();
return 0;
}
com =0x7fff15babf3c
10
com =0x7fff15babf3c
main=0x7fff15babf54
10