I have a template:
template <typename T, int size>
class Array
{
T A[size];
public:
T& operator[](int index) ;
};
template <typename T, int size>
T& Array<T,size>::operator[](int index)
{
if (index>=size || index<0)
return A[0];
else
return A[index];
}
And its specialisation class:
typedef struct Data
{
int id;
char name[10];
double temp;
double quantity;
}Data;
template <>
class Array<Data, int>
{
};
And I try to use it:
int main()
{
Array<Data, int> tab;
return 0;
}
But I'm getting this error, and dont really know why:
error: type/value mismatch at argument 2 in template parameter list for ‘template class Array’|
What's wrong?
Its strange. I changed the code to the following one:
template <>
class Array<Data, 20>
{
};
int main()
{
Array<Data, 20> tab;
return 0;
}
And its ok now. Thanks!