7

Regarding the following code:

void foo( int in )
{
  std::cout << "no ref" << std::endl;
}

void foo( int&& in )
{
  std::cout << "ref&&" << std::endl;
}


int main()
{ 
  foo( static_cast<int&&>(1) );

  return 0;
}

I wonder why the call to foo( static_cast< int&& >(1) ) is ambiguous:

error: call to 'foo' is ambiguous
  foo( static_cast<int&&>(1) );
  ^~~

Because of the explicit cast to int&&, I expected that void foo( int&& in ) will be called.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
abraham_hilbert
  • 2,221
  • 1
  • 13
  • 30

0 Answers0