Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 5 oop principles?

1073


What is overloading and its types?

1084


What is cohesion in oop?

1010


What is encapsulation in oop?

990


How do you explain polymorphism?

1017


Give two or more real cenario of virtual function and vertual object

2289


What is the advantage of oop over procedural language?

1009


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1866


when to use 'mutable' keyword and when to use 'const cast' in c++

2113


What is difference between polymorphism and inheritance?

1026


What language is oop?

967


What is balance factor?

1020


What is the difference between a mixin and inheritance?

936


What is polymorphism and example?

983


What is oops and its features?

1026