Do I have to explicitly indicate the type of the function template when it comes to deriving a reference type. If so, where is the ambiguity? Let me compare the following 2 code snippets:
1st: link for code
template <typename T>
void foo(T& var, void(*func)(T&))
{
++var;
}
void ret(int & var){}
int main()
{int k =7;
foo(k, &ret);
cout<<k;
}
Now let's remove both the foo () declaration and we have an error.
2nd: link for code
template <typename T>
void foo(T var, void(*func)(T))
{
++var;
}
void ret(int & var){}
int main()
{int k =7;
foo(k, &ret);
cout<<k;
}
However, if I call foo, explicitly creating an instance with <int&>
" foo<int&>(k,&ret);
", the code gives the same result as the first. What is the reason for this error? Where is the ambiguity?
Thanks.
source
share