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 does and I oop mean?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
The company is a fake company asking for money of RS10000 while training and not offering a job after training. My humble request to you people not to attend Astersys interview
what are the ways in which a constructors can be called?
When not to use object oriented programming?
What are constructors in oop?
Can we create object of abstract class?
What is polymorphism what is it for and how is it used?
Write a program to find out the number of palindromes in a sentence.
what is abstract class ? when is used in real time ? give a exp
create a c++ program that will accepts 9 inputs using 3 by 3 array.
c++ program to swap the objects of two different classes