fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5.  
  6. template <typename T>
  7. T maxn(const T[], const int);
  8.  
  9. template <> const char * maxn<char *>(const char * [], const int);
  10.  
  11.  
  12. int main(void)
  13. {
  14. using namespace std;
  15.  
  16.  
  17.  
  18. return 0;
  19. }
  20.  
  21. template <typename T>
  22. T maxn(const T arr[], int size)
  23. {
  24. T max = arr[0];
  25.  
  26. for (int i = 1; i < size; i++)
  27. if (arr[i] > arr[i - 1])
  28. max = arr[i];
  29.  
  30. return max;
  31. }
  32.  
  33. template <> const char * maxn<char *>(const char * arr[], int const size)
  34. {
  35. int imaxlength = 0;
  36. for (int i = 1; i < size; i++)
  37. {
  38. if (strlen(arr[i]) > strlen(arr[i - 1]))
  39. imaxlength = i;
  40. }
  41. return arr[imaxlength];
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:26: error: template-id ‘maxn<char*>’ for ‘const char* maxn(const char**, int)’ does not match any template declaration
 template <> const char * maxn<char *>(const char * [], const int);
                          ^~~~~~~~~~~~
prog.cpp:7:3: note: candidate is: template<class T> T maxn(const T*, int)
 T maxn(const T[], const int);
   ^~~~
prog.cpp:33:26: error: template-id ‘maxn<char*>’ for ‘const char* maxn(const char**, int)’ does not match any template declaration
 template <> const char * maxn<char *>(const char * arr[], int const size)
                          ^~~~~~~~~~~~
prog.cpp:22:3: note: candidate is: template<class T> T maxn(const T*, int)
 T maxn(const T arr[], int size)
   ^~~~
stdout
Standard output is empty