相关疑难解决方法(0)

当你完美前进时,typename T变为T&或T &&,但是当你不完美时,T根本就不是参考.怎么样?

我正在阅读关于完美转发的内容,这是我所学到的让我困惑的事情:
当你试图实现完美的转发时,你会做这样的事情:

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不是参考?有人可以告诉我这个的确切规则吗?我需要一些澄清!

c++ templates c++11

5
推荐指数
4
解决办法
416
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1