Wednesday, April 7, 2021

program using function templates (OOP) (41)

                            /* function templates in c++

                                  ****************************/

/*a function tamplates work with similer manner as simple function but one key difference. a single

function templates can work on different typesat once but different function needed to perform

are identical task on different data types.if you need to perform identical operation on two or 

more types of data then you can use function overloading. but better thing is that you would be use 

function templates with the use of function templates we can reduce the code and make the programm

more easy. A function template start with the the keyword "template". and use <> inside this we can

use "class" or "typename".*/

#include<iostream>

using namespace std;

template<typename i,typename d>

void sum(i x,d y)

{

cout<<x<<"+"<<y<<"="<<x+y<<endl;

}

int main()

{

sum(2,3);

    sum(2.5,3.6);

    sum(7.8,3);

sum(2,3.8);

} 

No comments:

Post a Comment