Can't compile function template on VC7.1
-
i want to compile this code :
template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; }
got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid??? -
i want to compile this code :
template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; }
got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid???Teerayoot wrote: template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; } put above code in header file !
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
i want to compile this code :
template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; }
got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid???try using as
template<typename T> inline const T& getMax ( const T& a, const T& b) { return a < b ? b : a ; }
The problem is with the name of the function. I have renamed it from "max" to "getMax" because macros with the name "min" and "max" already exist in stdlib.h, and same name of the function as those macros caused the errors. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan -
try using as
template<typename T> inline const T& getMax ( const T& a, const T& b) { return a < b ? b : a ; }
The problem is with the name of the function. I have renamed it from "max" to "getMax" because macros with the name "min" and "max" already exist in stdlib.h, and same name of the function as those macros caused the errors. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan