我正在阅读关于完美转发的内容,这是我所学到的让我困惑的事情:
当你试图实现完美的转发时,你会做这样的事情:
template<class T> // If I were to call foo with an l-value int, foo would look
void foo(T &&x); // like this: void foo(int& &&x)
Run Code Online (Sandbox Code Playgroud)
那么我想,等等,这是否意味着如果我这样做:
template<class T> // If I were to call foo with an l-value int, foo would look
void foo(T x); // like this: void foo(int& x);
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.foo看起来像这样:void foo(int x);
我的问题:为什么完美的转发功能,T变成T&或T &&,但在另一个,T不是参考?有人可以告诉我这个的确切规则吗?我需要一些澄清!