abr*_*ert 7 c++ overloading rvalue-reference
关于以下代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么呼叫foo( static_cast< int&& >(1) )是模棱两可的:
error: call to 'foo' is ambiguous
foo( static_cast<int&&>(1) );
^~~
Run Code Online (Sandbox Code Playgroud)
由于显式强制转换int&&,我预计void foo( int&& in )会被调用.