use of template in c 2b 2b

Solutions on MaxInterview for use of template in c 2b 2b by the best coders in the world

showing results for - "use of template in c 2b 2b"
Emer
24 Aug 2016
1// If two characters are passed to function template, character with larger ASCII value is displayed.
2
3#include <iostream>
4using namespace std;
5
6// template function
7template <typename T>
8T Large(T n1, T n2)
9{
10	return (n1 > n2) ? n1 : n2;
11}
12
13int main()
14{
15	int i1, i2;
16	float f1, f2;
17	char c1, c2;
18
19	cout << "Enter two integers:\n";
20	cin >> i1 >> i2;
21	cout << Large(i1, i2) <<" is larger." << endl;
22
23	cout << "\nEnter two floating-point numbers:\n";
24	cin >> f1 >> f2;
25	cout << Large(f1, f2) <<" is larger." << endl;
26
27	cout << "\nEnter two characters:\n";
28	cin >> c1 >> c2;
29	cout << Large(c1, c2) << " has larger ASCII value.";
30
31	return 0;
32}
queries leading to this page
how to create a template function in c 2b 2bdefining template functions in cppc 2b 2b template classc 2b 2b template referencec 2b 2b new program template keywordtemplates in cpptemplate function c 2b 2b examplec 2b 2b using 3d templatec 2b 2b templateshow to use templates in c 2b 2bc 2b 2b using with templatec 2b 2b definition template functionusing template class c 2b 2btemplate in cppusing a template c 2b 2bclasses with templates c 2b 2btemplate definition in c 2b 2bhow to add a template c 2b 2btemplate in function c 2b 2btypes of templates in c 2b 2bwhat is template function in c 2b 2bhow to create template class in c 2b 2bwhy we use template function in c 2b 2busage of templates c 2b 2bfunction template in c 2b 2btemplate in c 2b 2b structurewhere to declare template in c 2b 2btemplate function in c 2b 2btemplate function c 2b 2btemplate declaration c 2b 2bcreating templates in c 2b 2bmaking a new template function in cpptemplate on function c 2b 2btemplate syntax in c 2b 2btemplate c 2b 2btemplates in c 2b 2b guidec 2b 2b templates programfunctions in templates c 2b 2btemplates c 2b 2bwhat is a template in cppexplain advantage of using template in c 2b 2b 3fset template c 2b 2bhow to use template class in c 2b 2busing template in cp in c 2b 2bc 2b 2b template functionwhat are templates in c 2b 2btemplate t c 2b 2b exampletemplated function c 2b 2bhow to make a template function in c 2b 2btemplate of a reference c 2b 2btemplate example c 2b 2bfunction templates in c 2b 2bwrite a c 2b 2b program to rxplain the concept of templatetemplates in c 2b 2busing templates in classes c 2b 2bc 2b 2b template function examplec 2b 2b class templatestemplate class declaration c 2b 2bhow to declare template in c 2b 2bdeclaring a template function c 2b 2btemplates i n c 2b 2buse of template in c 2b 2b