C++ examples for template:template function
Creating a Template Function
#include <iostream> using namespace std; template <typename T> T Add(const T& a, const T& b) { return a + b; } int main(int argc, char* argv[]) { const int number1{ 1 }; const int number2{ 2 }; const int result{ Add(number1, number2) }; cout << "The result of adding" << endl; cout << number1 << endl; cout << "to" << endl; cout << number2 << endl; cout << "is" << endl; cout << result;/*from w w w . ja v a 2 s .c o m*/ return 0; }