这是我的代码:
#include<iostream>
template <typename T1, typename T2>
auto sum(const T1 &v1, const T2 &v2) -> decltype(v1 + v2)
{
return v1 + v2;
}
int main()
{
std::cout << sum(12, 123456789123456789123456789123456789123456789) << std::endl;
return 0;
}
以下是编制者的抱怨:
[Error] ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and '<unnamed-signed:128>')
当我将sum的seconed参数更改为12时,此代码编译无怨言。