Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename T>
- T add(T, T); // прототип функции
- ///////////////////////////////////////////////////////////////
- int main()
- {
- cout << "int: " << add(4, 5) << endl;
- cout << "double: " << add(4.4, 5.5) << endl;
- cout << "string: " << add(string("hel"), string("lo")) << endl;
- }
- template<typename T>
- ////////////////////////////
- T add(T a, T b)
- {
- return a + b;
- }
- /*
- #include <iostream>
- using namespace std;
- int add(int, int);
- double add(double, double);
- std::string add(std::string, std::string);
- ////////////////////////////////////////////
- int main()
- {
- std::cout << "int: " << add(4, 5) << std::endl;
- std::cout << "double: " << add(4.4, 5.5) << std::endl;
- std::cout << "string: " << add(std::string("hel"), std::string("lo")) << std::endl;
- }
- ////////////////////////////////////////////
- int add(int x, int y)
- {
- return x + y;
- }
- ////////////////////////////////////////////
- double add(double x, double y)
- {
- return x + y;
- }
- ////////////////////////////////////////////
- std::string add(string str1, string str2)
- {
- return str1 + str2;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement