vendredi 3 juillet 2015

Confusion with universal references

I have this code:

void f2(int& lvalue)
{
  std::cout <<"lvalue\n";
}
void f2(int&& rvalue)
{
  std::cout << "rvalue\n";
}

template<typename T>
void f(T&& param)
{
  f2(param);
}

I expect to get "lvalue" if I call f with:

int v = 10;
f(v);

and expect "rvalue" if I call f with:

f(10);

However, I always get the lvalue case. Please, can anybody explain where I'm wrong.

Aucun commentaire:

Enregistrer un commentaire