vendredi 22 juillet 2016

Why does && sometimes bind lvalues and other times not?

Ok I have this code:

struct Mine{
    template<typename T>
    Mine(T&& x){
    }
};
void nFoo(int&& x){
}
void sFoo(Mine x){
}

The nFoo takes an int&& directly, while the sFoo does some finagling to get the same effect.

Consider this code:

nFoo(12); //Works

int x = 0;
nFoo(x);  //Cannot bind int (lvalue) to int&&

sFoo(12); //Works
sFoo(x);  //Works

Why does the int&& sometimes allow binding from lvalues and sometimes not?

Aucun commentaire:

Enregistrer un commentaire