Reputation: 45
I've read that could be a issue of IntelliSense, but I really don't know is it true or not. When I compile the code, I get an error (title) and don't know how to fix it. My book (Stephen Prata's "Sams C++ Primer Plus") doesn't answer to my problem. I've wrote a pretty similar program and the problem didn't appear.
Maybe the problem is in type specifier? Has it be the same as template's one? REALLY sorry for my language...
#include <iostream>
template <typename T>
T maxn(T tab[], int size);
template <> float maxn<float>(float, int); // Problem appears here...
int main()
{
std::cin.get();
return 0;
}
template <typename T>
T maxn(T tab[], int size)
{
T max = tab[0];
for (int i = 1; i < size; i++)
{
if (tab[i] > max) max = tab[i];
}
}
I appreciate any suggestion. Thanks!
Upvotes: 1
Views: 8951
Reputation: 168958
The first argument of the specialization is incorrect. You give float
but according to the template it should be an array of floats.
template <> float maxn<float>(float[], int);
// ^
// You need to indicate that the first parameter is an array.
Note that you do not declare a body for the specialization, so linking will fail if you attempt to use it. (Unless you are providing an implementation in another compilation unit.)
Upvotes: 3