Advertisement
dllbridge

Untitled

Jul 26th, 2023
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. template<typename T>
  8. T add(T, T);                                // прототип функции
  9.  
  10.  
  11.  
  12. ///////////////////////////////////////////////////////////////
  13. int main()
  14. {
  15.     cout <<    "int: " << add(4, 5)     << endl;
  16.     cout << "double: " << add(4.4, 5.5) << endl;
  17.     cout << "string: " << add(string("hel"), string("lo")) << endl;
  18. }
  19.  
  20.  
  21.  
  22. template<typename T>
  23. ////////////////////////////
  24. T add(T a, T b)
  25. {
  26.     return a + b;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. /*
  35. #include <iostream>
  36. using namespace std;
  37.  
  38. int add(int, int);
  39. double add(double, double);
  40. std::string add(std::string, std::string);
  41.  
  42.  
  43.  
  44. ////////////////////////////////////////////
  45. int main()
  46. {
  47.     std::cout << "int: " << add(4, 5) << std::endl;
  48.     std::cout << "double: " << add(4.4, 5.5) << std::endl;
  49.     std::cout << "string: " << add(std::string("hel"), std::string("lo")) << std::endl;
  50. }
  51.  
  52.  
  53. ////////////////////////////////////////////
  54. int add(int x, int y)
  55. {
  56.     return x + y;
  57. }
  58.  
  59.  
  60. ////////////////////////////////////////////
  61. double add(double x, double y)
  62. {
  63.     return x + y;
  64. }
  65.  
  66. ////////////////////////////////////////////
  67. std::string add(string str1, string str2)
  68. {
  69.     return str1 + str2;
  70. }
  71. */
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement