Is there a way to let the compiler distinguish whether the passed variable is a reference or not, without explicitly specifying it using e.g. <int &>? The following example displays '1', whereas I expected a '2':
template <typename Type>
void fun(Type)
{
cout << 1 << '\n';
}
template <typename Type>
void fun(Type &)
{
cout << 2 << '\n';
}
int main()
{
int x = 0;
int &ref = x;
fun(ref);
}
I also tried to use std::ref, but I don't get it to work.