Hi,
The following code doesnt seem to compile
template <typename Type, int size>
Type min(Type (&arr)[size])
{
}
The error says
error C2265: '<Unknown>' : reference to a zero-sized array is illegal
Any suggestions
Thanks.
KarthikR

Compile time error for size parameter in templates
C. McGrunty
The problemis that min might be already defined as a macro.
try
#undef min
template <typename Type, int size>
Type min(Type (&arr)[size])
{
}
Or use an other name for min like mymin, xmin or whatever.
excittor
The following code compiles fine on VC 2005
template <typename Type, int size> Type Min(Type (&arr)[size])
{
return ' ';
}
int main()
{
char y[10];
Min<char, 10>(y);
return 0;
}
Bocman
Okay - VC 6 is pretty bad at handling some of the template related stuff. Upgrade to VC++ 2005 if you can, it's definitely worth it.
Vales
Sorry I should of replied to you. I replied to Nishant instead. But the point is that the same code doesnt compile on Visual C++ 6.0
Catherine Sea
I believe the reason for your problem is stated in the error message:
"reference to a zero-sized array is illegal".
Make sure that you are passing in an array with well defined, non-zero size. See Nish's code abover for an example.
SuperNova298
Thanks for the reply.
Doesnt seem to help. I changed the name of the function to min1 and it still gives the same error.
Thanks,
KarthikR
vbman
Rafayel
I copied your exact code and it doesnt compile on Visual C++ 6.0,
Anyways,
Thanks all for the response.
KarthikR