我试图理解右值引用和移动语义.在下面的代码中,当我将10传递给Print函数时,它会调用rvalue reference overload,这是预期的.但究竟发生了什么,10将被复制(或从它引用的地方).其次std :: move实际上做了什么?它从i中提取值10然后通过吗?或者是编译器使用右值参考的指令?
void Print(int& i) { cout<<"L Value reference "<<endl; } void Print(int&& i) { cout<<"R Value reference "<< endl; } int main() { int i = 10; Print(i); //OK,understandable Print(10); //will 10 is not getting copied? So where it will stored Print(std::move(i)); //what does move exactly do return 0; }
谢谢.
@H_502_6@