C++ Logo


Advanced search

Subject: Not understanding rvalue reference matching rules in overloaded functions.
From: Edward Diener (eldlistmailingz_at_[hidden])
Date: 2021-06-01 08:54:51

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 ?

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups