我知道转发引用是“对cv不合格模板参数的右值引用”,例如
template <class T> void foo(T&& );
Run Code Online (Sandbox Code Playgroud)
这意味着上述函数可以同时使用l值和r值参考。
我有些不懂的事,例如
template <class T>
class A
{
template <class U>
void foo(T&& t, U&& u)
{
T t2( std::forward(t) ); // or should it be std::move(t)? is T&& forwarding or r-value reference
U u2( std::forward(u) ); // or should it be std::move(u)? I believe U&& is forwarding reference
}
};
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,T &&和U &&都是转发参考吗?
我写了一些代码进行测试(VS2015编译器):
class A
{
public:
A(){};
A(const A& rhs)
{
std::cout << "calling 'const A&' l-value" << std::endl; …Run Code Online (Sandbox Code Playgroud)