虎吼txt下载,农夫导航不准打火机,周黛莲
forward() 函数的作用:它接受一个参数,然后返回该参数本来所对应的类型的引用。
下面的例子就不能够调用
void rvalue_call(int&& v)
void rvalue_call(const int&& v)
include <iostream> using namespace std; void rvalue_call(int& v){ cout << "& call" << endl; } void rvalue_call(int&& v){ cout << "&& call" << endl; } void rvalue_call(const int& v){ cout << "const & call" << endl; } void rvalue_call(const int&& v){ cout << "const && call" << endl; } template<typename t> void func(t&& a){ rvalue_call(a); } int main(void){ int x = 1; func(x);//实参为左值 int& y = x; func(y);//实参为左值引用 func(std::move(y));//实参为右值引用 func(100);//实参为右值引用 const int a = 11; func(a);//实参为左值常引用 func(std::move(a));//实参为右值常引用 }
#include <iostream> using namespace std; void rvalue_call(int& v){ cout << "& call" << endl; } void rvalue_call(int&& v){ cout << "&& call" << endl; } void rvalue_call(const int& v){ cout << "const & call" << endl; } void rvalue_call(const int&& v){ cout << "const && call" << endl; } template<typename t> void func(t&& a){ rvalue_call(std::forward<t> (a)); } int main(void){ int x = 1; func(x);//实参为左值 int& y = x; func(y);//实参为左值引用 func(std::move(y));//实参为右值引用 func(100); const int a = 11; func(a); func(std::move(a)); }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论