what is the difference between function template and
template of function?explain with example.

Answers were Sorted based on User's Feedback



what is the difference between function template and template of function?explain with example...

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 is the difference between function template and template of function?explain with example...

Answer / sree

its write

Is This Answer Correct ?    8 Yes 7 No

Post New Answer

More OOPS Interview Questions

write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.

4 Answers  


Whats is abstraction in oops?

0 Answers  


What are two types of polymorphism?

0 Answers  


what is new operator in c++

1 Answers  


what isthe difference between c structure and c++ class

5 Answers  






There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

2 Answers  


Contrast OOP and SOA. What are tenets of each?

1 Answers   Siebel Systems, Wipro,


Which type does string inherit from?

0 Answers  


sir i want to know which posting to apply since i am BE CSE.. also want to know what are the rounds there for my interview...Expecting for ur valuable answer....

2 Answers  


what is the technical or oop name of object?

1 Answers  


How do you use inheritance in unity?

0 Answers  


WHAT IS THE ACTUAL DEFINATION OF OBJECT AND THE CLASS IN ONE SINGLE LINE WHICH THE INTERVIEWER WANT TO LISTEN.

11 Answers  


Categories