任何人都可以解释为什么编译器(g ++,visual c ++)在这种情况下无法推断模板参数?
struct MyClass
{
void Foo(int x)& {}
void Foo(int x)&& {}
};
template<typename T>
void CallFoo(void(T::*func)(int)&)
{
//create instance and call func
}
int main()
{
CallFoo(&MyClass::Foo); // Fails to deduce T
}
Run Code Online (Sandbox Code Playgroud)
为什么编译器不能将T推导为MyClass?这仅适用于ref限定符重载的方法.如果方法被const-ness或参数类型重载,一切正常.在这种情况下,似乎只有Clang才能推断T.