samedi 4 février 2017

Why is rval ref binding to lval ref function ?

In the code below, is_rvalue_reference returns true. I would expect testRef(int &&) to be called and not testRef(int &), but that's not the case (at least with my Visual Studio 2015 compiler).

Any idea of the reason why ?

void testRef( int&& i )
{
    cout << "called testRef(int&&) " << endl;
}

void testRef( int& i )
{
    cout << "called testRef(int&) " << endl;
}

int main()
{
    int && rvalref = 4;
    cout << "is rval? : " << std::is_rvalue_reference<decltype( rvalref )>() << endl;
    testRef( rvalref );
}

Aucun commentaire:

Enregistrer un commentaire