【发布时间】:2013-04-12 10:16:22
【问题描述】:
我正在试验新添加的右值引用(在 vs2012 express 中)。
我有些不明白。给定下面的代码(其中大部分来自解释 std::forward 的 c++ 标准)。
struct A
{
A(int& i, const float& j):
m_i(i),
m_j(j){}
int& m_i;
const float& m_j;
};
template<class T, class A1, class A2>
T* factory(A1&& a1, A2&& a2)
{
return new T(a1, a2);
}
void test()
{
A* a1 = factory<A>(1, 1.2f);
//How does this work ?
a1->m_i = 2;
}
我不明白 m_i 绑定到哪里。
我基本上会有一个对右值引用 (& &&) 的左值引用,通过 ref 折叠规则变成 (&) 只是一个普通的左值 ref。但是参考什么?
【问题讨论】: