Consider this program:
template<typename T>
struct Foo
{
void foo(const T&) {}
void foo(T&) {}
};
int main()
{
Foo<double&> f;
double d = 3.14;
f.foo(d); //complains that foo() is ambigous
}
In the above, if Foo is instantiated as Foo<double>
, then things are fine, but if it is instantiated as Foo<double&>
, then the call to foo
becomes ambiguous. Is ref collapsing at play here when deducing the param types for foo
and if so why is constness being ignored?