Šablony funkcí I

{“https:\/\/www.jdoodle.com\/a\/aaj?format=text”:”#include <iostream>\nusing namespace std;\n\ntemplate<typename T> \nvoid swapValues(T& a, T& b) {\n T tmp = a;\n a = b;\n b = tmp;\n}\n\nint main() {\n int a = 1, b = 2;\n cout << "a = " << a << ", b = " << b << endl;\n swapValues<int>(a, b);\n cout << "a = " << a << ", b = " << b << endl;\n cout << endl;\n \n double aa = 1.5, bb = 2.4;\n cout << "aa = " << aa << ", bb = " << bb << endl;\n swapValues<double>(aa, bb);\n cout << "aa = " << aa << ", bb = " << bb << endl;\n cout << endl;\n \n string sa("SA"), sb("SB");\n cout << "sa = " << sa << ", sb = " << sb << endl;\n swapValues<string>(sa, sb);\n cout << "sa = " << sa << ", sb = " << sb << endl;\n \n return 0;\n}\n”,”https:\/\/www.jdoodle.com\/a\/adG?format=text”:”#include <iostream>\nusing namespace std;\n\ntemplate<typename T> \nvoid swapValues(T& a, T& b) {\n T tmp = a;\n a = b;\n b = tmp;\n}\n\nint main() {\n double aa = 1.5, bb = 2.4;\n cout << "aa = " << aa << ", bb = " << bb << endl;\n swapValues(aa, bb);\n cout << "aa = " << aa << ", bb = " << bb << endl;\n cout << endl;\n \n string sa("SA"), sb("SB");\n cout << "sa = " << sa << ", sb = " << sb << endl;\n swapValues(sa, sb);\n cout << "sa = " << sa << ", sb = " << sb << endl;\n \n return 0;\n}\n”}


Šablony funkcí I
Ohodnoťte tento článek