Assuming I have the following code below.
template <class T> T maxn(T num[], int n)
{
T largest = num[0];
while (n-- > 0)
{
if (num[n] > largest)
largest = num[n];
}
return largest;
}
template <> char * maxn(char *string[], int n)
{
char *longest = string[0];
while (n-- > 0)
{
if (strlen(string[n]) > strlen(longest))
longest = string[n];
}
return longest;
}
Why do I really need the template <> declaration in front of the second function to say it's a specialization? If I take out the template <> it still compiles and works the same. Can someone clarify this for me?