samedi 16 décembre 2017

c++ why does std::move take rvalue reference as argument?

According to cppreference.com, move has signature

template< class T >
typename std::remove_reference<T>::type&& move( T&& t ) noexcept;

Why does it take a rvalue reference T&& t as its arugment?

Also when I tried the following code

void foo(int&& bar) {
    cout << "baz" << endl;
}

int main(){
    int a;
    foo(a);
}

I got an error from the compiler "an rvalue reference cannot be bound to an lvalue"

What is going on? I'm so confused.

Aucun commentaire:

Enregistrer un commentaire