what is the difference between function template and
template of function?explain with example.
Answers were Sorted based on User's Feedback
Answer / subhashish
Function Template is a mechanism by which you can write
generic programs.Means you only need to create one framework
and based on your requirement you can write many
implementations.
one Framework is called Function Template.
Each implementation(function call) is called Template
Functions.
For your reference see the example below..
EX:
template <class T>
void swap(T &a,T &b) <----//This is Function Template.
{ T temp;
temp = a;
a = b;
b = temp;
}
int main()
{
int i1 = 5,i2 = 6;
float f1 = 2.2,f2 = 5.5;
char c1 = 'A',c2 = 'B';
cout<<"Before swapping i1 ="<<i1<<" i2 ="<<i2;
swap(i1,i2); <-----//This is 1 Template Function
cout<<"After swapping i1 ="<<i1<<" i2 ="<<i2;
cout<<"Before swapping f1 ="<<f1<<" f2 ="<<f2;
swap(f1,f2); <-----//This is 2 Template Function
cout<<"After swapping f1 ="<<f1<<" f2 ="<<f2;
cout<<"Before swapping c1 ="<<c1<<" c2 ="<<c2;
swap(c1,c2); <-----//This is 3 Template Function
cout<<"After swapping c1 ="<<c1<<" c2 ="<<c2;
return 0;
}
| Is This Answer Correct ? | 37 Yes | 7 No |
what are the disadvantages of C++?
25 Answers ATS, Infosys, UNI, Wipro,
#include <iostream> using namespace std; int main() { int a = 3; int c[5][5]; for (int x=0;x<5;x++) { for (int y=0;y<5;y++) { c[x][y] = x*y; } } cout << c[a][2]; }
Iam doing my project on instant messaging , if you any new ideas regarding this project ,please suggest it?
What is data binding in oops?
any one please tell me the purpose of operator overloading
What is object and class in oops?
What does and I oop mean in text?
Why is object oriented programming so hard?
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321
Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 1 212 32123 4321234 543212345
to find out the minimum of two integer number of two different classes using friend function
write a program for function overloading?
14 Answers HCL, InfoCity, TATA,