CPP   16

sablon cpp

Guest on 5th July 2022 05:00:18 PM

  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. template<class T1>
  7. T maksimum(T1 x, T2 y) {
  8.   return x > y ? x : y;
  9. }
  10.  
  11. char* maksimum(char *x, char *y) {
  12.   return strcmp(x, y) > 0 ? x : y;
  13. }
  14.  
  15.  
  16. int main() {
  17.   int a = 2, b = 3;
  18.   cout << "max(a, b) = " << maksimum(a, b) << endl;
  19.   cout << "max(a, b) = " << maksimum<int>(a, b) << endl;
  20.  
  21.   double c = 2.2, d = 3.3;
  22.   cout << "max(c, d) = " << maksimum(c, d) << endl;
  23.   cout << "max(c, d) = " << maksimum<double>(c, d) << endl;
  24.   cout << "max(c, d) = " << maksimum<int>(c, d) << endl;
  25.  
  26.   //cout << "max(a, c) = " << maksimum(a, c) << endl;
  27.   cout << "max(a, c) = " << maksimum<double>(a, c) << endl;
  28.   cout << "max(a, c) = " << maksimum<int>(a, c) << endl;
  29.  
  30.   char *s = "mirko";
  31.   char *t = "spasic";
  32.   cout << "max(s, t) = " << maksimum(s, t) << endl;
  33.  
  34.   return 0;
  35. }

Raw Paste


Login or Register to edit or fork this paste. It's free.