我很惊讶以下代码导致could not deduce template argument for T错误:
struct foo
{
template <typename T>
void bar(int a, T b = 0.0f)
{
}
};
int main()
{
foo a;
a.bar(5);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调用a.bar<float>(5)解决了这个问题.为什么编译器不能从默认参数中推断出类型?