D
Dennis Pais
Here's a piece of code that I found in C++ Primer by Stan Lippman !
-------------------------------------------------
template<typename T, int size>
T min(T (&r_array) [size] )
{
Type min_value = r_array[0];
for(int i=1; i<size; i++)
{
if( r_array < min_value)
min_value = r_array;
}
return min_value;
}
int ia[] = {1,2,3,4,5,6};
//to invoke the above function
int main()
{
int i = min(ia);
printf("Hello World");
}
-------------------------------------------------
I am working with a Microsoft compiler (VC++ 6.0), & the above code
fails to compile with the following error(s):
--------------------------------------------------------------
E:\TEMPLATES\Templates\Templates.cpp(91) : error C2265: '<Unknown>' :
reference to a zero-sized array is illegal
E:\TEMPLATES\Templates\Templates.cpp(124) : error C2784: 'T __cdecl
min(T (&)[1])' : could not deduce template argument for ' (&)[1]' from
'int [5]'
Error executing cl.exe.
---------------------------------------------------------------
Can someone tell me if the above code works with some other
non-Microsoft compiler & why the Microsoft compiler does not allow
this code to execute ?
-Thanks
Dennis
-------------------------------------------------
template<typename T, int size>
T min(T (&r_array) [size] )
{
Type min_value = r_array[0];
for(int i=1; i<size; i++)
{
if( r_array < min_value)
min_value = r_array;
}
return min_value;
}
int ia[] = {1,2,3,4,5,6};
//to invoke the above function
int main()
{
int i = min(ia);
printf("Hello World");
}
-------------------------------------------------
I am working with a Microsoft compiler (VC++ 6.0), & the above code
fails to compile with the following error(s):
--------------------------------------------------------------
E:\TEMPLATES\Templates\Templates.cpp(91) : error C2265: '<Unknown>' :
reference to a zero-sized array is illegal
E:\TEMPLATES\Templates\Templates.cpp(124) : error C2784: 'T __cdecl
min(T (&)[1])' : could not deduce template argument for ' (&)[1]' from
'int [5]'
Error executing cl.exe.
---------------------------------------------------------------
Can someone tell me if the above code works with some other
non-Microsoft compiler & why the Microsoft compiler does not allow
this code to execute ?
-Thanks
Dennis