C++ Logo

std-discussion

Advanced search

Not understanding rvalue reference matching rules in overloaded functions.

From: Edward Diener <eldlistmailingz_at_[hidden]>
Date: Tue, 1 Jun 2021 09:54:51 -0400
The code:

#include <iostream>
#include <utility>

void afunc(int)
     {
     std::cout << "\nafunc(int)\n";
     }

void afunc(int &&)
     {
     std::cout << "\nafunc(int &&)\n";
     }

int main()
   {

   int i = 0;

   afunc(std::move(i));
   }

The result is an error saying that the call to 'afunc' is ambiguous.
Since std::move creates an rvalue reference and one of the overloads to
afunc takes an rvalue reference, for an exact match, I do not understand
the error. Would someone please explain and cite the section of the
C++11 standard which explains why the exact match is an equal match to
the other overload, thereby causing ambiguity ?

Received on 2021-06-01 08:54:58