Search This Blog

Read Your Language

How to write template in C++?

How to write  template in C++?

#include<iostream>
using namespace std;
template <class t1, class t2>
class template1
{
t1 x;
t2 y;
public :
template1(t1 a ,t2 b )
{
x=a;
y=b;
}
void display()
{
cout<<x<<" and "<<y<<endl;
}
};
main()
{
template1<float, int > test1(4.34,543);
template1<int ,char> test2 (800, 'h');
test1.display();
test2.display();
return 0;
}

OUTPUT:

4.34 and 543
800 and h 

No comments:

Contact Form

Name

Email *

Message *

Followers