I'm doing C ++ exercises and I've created a template for the function to return 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 type char *, and gives the following model:
template <>
Tipo funcao<Tipo>(Tipo param1, Tipo param2, ...) { ... }
Type is the concrete type to be used in the specialization (int, double, char *, etc.).
Step 6: (Challenge 1) Specialize the max () function to handle char * using the syntax above. Use the function strcmp (); you must include cstring. Make changes to main () to test these functions. Compile and test next.
But I can not do it. My role was:
template <>
char * maximo<char *>(const char *a, const char *b) {
if (strcmp(a ,b) < 0) {
return a;
}
return b;
}