我有3个问题:绑定修改的右值引用到修改的左值
我可以一个左值直接绑定到一个右值引用?
会发生什么事的对象是
std::move()
?什么的std ::移动和
std::forward
之间的区别?
struct myStr{
int m_i;
};
void foo(myStr&& rs) { }
myStr rValueGene()
{
return myStr();
}
int main()
{
myStr mS= {1};
foo(rValueGene()); //ok passing in modifiable rvalue to rvalue reference
// To Question 1:
//below initilize rvalue reference with modifiable lvalue, should be ok
//but VS2010 gives a compile error: error C2440: 'initializing' : cannot convert from 'myStr' to 'myStr &&'
//Is this correct ?
myStr&& rvalueRef = mS;
//by using std::move it seems ok, is this the standard way of doing this
//to pass a lvalue to rvalue reference
//myStr&& rvalueRef = std::move(mS);
// To Question 2:
//also what happens to mS object after std::move ?
//destroyed , undefined ?
}