Explicit reference to r-value does not eliminate ambiguity

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 calling foo( static_cast< int&& >(1) ) ambiguous:

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

Due to the explicit cast to int&& I expected void foo( int&& in ) be called.

+7
c ++ rvalue-reference function-overloading
source share

No one has answered this question yet.

See similar questions:

54
Overload resolution between object, rvalue reference, link constant

or similar:

2387
What does an explicit keyword mean?
1492
Does Java support default parameter values?
31
Why does autoboxing make some calls ambiguous in Java?
twenty
Why does the overload function generate an ambiguous error in C ++?
5
How to define insert operators for all C ++ IOStream manipulators?
2
Why is this function overloaded with an error in C ++?
2
Why does the compiler complain about the ambiguity of an overloaded function?
one
Ambiguity when overloading a broadcast operator
0
C ++ heap / stack. Why only one new operator?
-4
How can I fix this Expected '(' to cast a function type or type construct?

All Articles