Dar*_*bik 3 c++ rvalue lvalue rvalue-reference
好的,我有这个代码:
struct Mine{
template<typename T>
Mine(T&& x){
}
};
void nFoo(int&& x){
}
void sFoo(Mine x){
}
Run Code Online (Sandbox Code Playgroud)
将nFoo需要一个int&&直接,而sFoo做一些finagling来获得同样的效果.
考虑以下代码:
nFoo(12); //Works
int x = 0;
nFoo(x); //Cannot bind int (lvalue) to int&&
sFoo(12); //Works
sFoo(x); //Works
Run Code Online (Sandbox Code Playgroud)
为什么int&&有时允许从lvalues 绑定,有时不允许绑定?