我有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 ?
}