0
I am doing C++ exercises and created a template for the function of returning the highest value.
template<class Type>
Type maximo (const Type a, const Type b) {
if (a > b) {
return a;
}
return b;
Now the list of exercises asks me to specialize the function to work with the char type *, and gives the following template:
template <>
Tipo funcao<Tipo>(Tipo param1, Tipo param2, ...) { ... }
Type is the concrete type to be used in specialization ( int , double , char * etc.).
Step 6: (Challenge 1) Specialize the maximum function() to handle char * using the above syntax. Use the strcmp() function; you need to include cstring. Make modifications to main() to test these functions. Compile and test next.
But I can’t make it turn. My function was:
template <>
char * maximo<char *>(const char *a, const char *b) {
if (strcmp(a ,b) < 0) {
return a;
}
return b;
}