1

Can anyone please explain me the difference between this 2 functions?

template<typename T>
void f(T&& a) {
}


void f(int&& a) {
}

int main(){
    int a = 3;
    f(a);
}

If I only have the template version, the code compiles and works fine.
But if I remove the template and leave the int&& version, the compiler complains and I have to
transform the call into f(std::move(a)) in order to make it work.
Can anyone please explain me the difference here?
Thanks in advance.

Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76
  • 2
    https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers – Alexander May 21 '20 at 20:08
  • 1
    [this blog](https://blog.petrzemek.net/2016/09/17/universal-vs-forwarding-references-in-cpp/) explains a bit of the history of the names. Imho its a pity that Scotts articles still call them "universal", which can be confusing at first, on the other hand it is his "fault" that they got a name in the first place – 463035818_is_not_an_ai May 21 '20 at 20:14

0 Answers0